intl-tel-input 20.2.0 → 21.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.
@@ -1,1864 +0,0 @@
1
- /*
2
- * International Telephone Input v20.2.0
3
- * https://github.com/jackocnr/intl-tel-input.git
4
- * Licensed under the MIT license
5
- */
6
-
7
- // wrap in UMD
8
- (function(factory) {
9
- if (typeof module === "object" && module.exports) {
10
- module.exports = factory(require("jquery"));
11
- } else if (typeof define === "function" && define.amd) {
12
- define([ "jquery" ], function($) {
13
- factory($);
14
- });
15
- } else factory(jQuery);
16
- })(function($, undefined) {
17
- "use strict";
18
- // Array of country objects for the flag dropdown.
19
- // Here is the criteria for the plugin to support a given country/territory
20
- // - It has an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
21
- // - It has it's own country calling code (it is not a sub-region of another country): https://en.wikipedia.org/wiki/List_of_country_calling_codes
22
- // - It has a flag in the region-flags project: https://github.com/behdad/region-flags/tree/gh-pages/png
23
- // - It is supported by libphonenumber (it must be listed on this page): https://github.com/googlei18n/libphonenumber/blob/master/resources/ShortNumberMetadata.xml
24
- // Each country array has the following information:
25
- // [
26
- // Country name,
27
- // iso2 code,
28
- // International dial code,
29
- // Order (if >1 country with same dial code),
30
- // Area codes
31
- // ]
32
- var allCountries = [ [ "Afghanistan", "af", "93" ], [ "Albania", "al", "355" ], [ "Algeria", "dz", "213" ], [ "American Samoa", "as", "1", 5, [ "684" ] ], [ "Andorra", "ad", "376" ], [ "Angola", "ao", "244" ], [ "Anguilla", "ai", "1", 6, [ "264" ] ], [ "Antigua & Barbuda", "ag", "1", 7, [ "268" ] ], [ "Argentina", "ar", "54" ], [ "Armenia", "am", "374" ], [ "Aruba", "aw", "297" ], [ "Ascension Island", "ac", "247" ], [ "Australia", "au", "61", 0 ], [ "Austria", "at", "43" ], [ "Azerbaijan", "az", "994" ], [ "Bahamas", "bs", "1", 8, [ "242" ] ], [ "Bahrain", "bh", "973" ], [ "Bangladesh", "bd", "880" ], [ "Barbados", "bb", "1", 9, [ "246" ] ], [ "Belarus", "by", "375" ], [ "Belgium", "be", "32" ], [ "Belize", "bz", "501" ], [ "Benin", "bj", "229" ], [ "Bermuda", "bm", "1", 10, [ "441" ] ], [ "Bhutan", "bt", "975" ], [ "Bolivia", "bo", "591" ], [ "Bosnia & Herzegovina", "ba", "387" ], [ "Botswana", "bw", "267" ], [ "Brazil", "br", "55" ], [ "British Indian Ocean Territory", "io", "246" ], [ "British Virgin Islands", "vg", "1", 11, [ "284" ] ], [ "Brunei", "bn", "673" ], [ "Bulgaria", "bg", "359" ], [ "Burkina Faso", "bf", "226" ], [ "Burundi", "bi", "257" ], [ "Cambodia", "kh", "855" ], [ "Cameroon", "cm", "237" ], [ "Canada", "ca", "1", 1, [ "204", "226", "236", "249", "250", "263", "289", "306", "343", "354", "365", "367", "368", "382", "387", "403", "416", "418", "428", "431", "437", "438", "450", "584", "468", "474", "506", "514", "519", "548", "579", "581", "584", "587", "604", "613", "639", "647", "672", "683", "705", "709", "742", "753", "778", "780", "782", "807", "819", "825", "867", "873", "902", "905" ] ], [ "Cape Verde", "cv", "238" ], [ "Caribbean Netherlands", "bq", "599", 1, [ "3", "4", "7" ] ], [ "Cayman Islands", "ky", "1", 12, [ "345" ] ], [ "Central African Republic", "cf", "236" ], [ "Chad", "td", "235" ], [ "Chile", "cl", "56" ], [ "China", "cn", "86" ], [ "Christmas Island", "cx", "61", 2, [ "89164" ] ], [ "Cocos (Keeling) Islands", "cc", "61", 1, [ "89162" ] ], [ "Colombia", "co", "57" ], [ "Comoros", "km", "269" ], [ "Congo - Brazzaville", "cg", "242" ], [ "Congo - Kinshasa", "cd", "243" ], [ "Cook Islands", "ck", "682" ], [ "Costa Rica", "cr", "506" ], [ "Côte d’Ivoire", "ci", "225" ], [ "Croatia", "hr", "385" ], [ "Cuba", "cu", "53" ], [ "Curaçao", "cw", "599", 0 ], [ "Cyprus", "cy", "357" ], [ "Czech Republic", "cz", "420" ], [ "Denmark", "dk", "45" ], [ "Djibouti", "dj", "253" ], [ "Dominica", "dm", "1", 13, [ "767" ] ], [ "Dominican Republic", "do", "1", 2, [ "809", "829", "849" ] ], [ "Ecuador", "ec", "593" ], [ "Egypt", "eg", "20" ], [ "El Salvador", "sv", "503" ], [ "Equatorial Guinea", "gq", "240" ], [ "Eritrea", "er", "291" ], [ "Estonia", "ee", "372" ], [ "Eswatini", "sz", "268" ], [ "Ethiopia", "et", "251" ], [ "Falkland Islands", "fk", "500" ], [ "Faroe Islands", "fo", "298" ], [ "Fiji", "fj", "679" ], [ "Finland", "fi", "358", 0 ], [ "France", "fr", "33" ], [ "French Guiana", "gf", "594" ], [ "French Polynesia", "pf", "689" ], [ "Gabon", "ga", "241" ], [ "Gambia", "gm", "220" ], [ "Georgia", "ge", "995" ], [ "Germany", "de", "49" ], [ "Ghana", "gh", "233" ], [ "Gibraltar", "gi", "350" ], [ "Greece", "gr", "30" ], [ "Greenland", "gl", "299" ], [ "Grenada", "gd", "1", 14, [ "473" ] ], [ "Guadeloupe", "gp", "590", 0 ], [ "Guam", "gu", "1", 15, [ "671" ] ], [ "Guatemala", "gt", "502" ], [ "Guernsey", "gg", "44", 1, [ "1481", "7781", "7839", "7911" ] ], [ "Guinea", "gn", "224" ], [ "Guinea-Bissau", "gw", "245" ], [ "Guyana", "gy", "592" ], [ "Haiti", "ht", "509" ], [ "Honduras", "hn", "504" ], [ "Hong Kong", "hk", "852" ], [ "Hungary", "hu", "36" ], [ "Iceland", "is", "354" ], [ "India", "in", "91" ], [ "Indonesia", "id", "62" ], [ "Iran", "ir", "98" ], [ "Iraq", "iq", "964" ], [ "Ireland", "ie", "353" ], [ "Isle of Man", "im", "44", 2, [ "1624", "74576", "7524", "7924", "7624" ] ], [ "Israel", "il", "972" ], [ "Italy", "it", "39", 0 ], [ "Jamaica", "jm", "1", 4, [ "876", "658" ] ], [ "Japan", "jp", "81" ], [ "Jersey", "je", "44", 3, [ "1534", "7509", "7700", "7797", "7829", "7937" ] ], [ "Jordan", "jo", "962" ], [ "Kazakhstan", "kz", "7", 1, [ "33", "7" ] ], [ "Kenya", "ke", "254" ], [ "Kiribati", "ki", "686" ], [ "Kosovo", "xk", "383" ], [ "Kuwait", "kw", "965" ], [ "Kyrgyzstan", "kg", "996" ], [ "Laos", "la", "856" ], [ "Latvia", "lv", "371" ], [ "Lebanon", "lb", "961" ], [ "Lesotho", "ls", "266" ], [ "Liberia", "lr", "231" ], [ "Libya", "ly", "218" ], [ "Liechtenstein", "li", "423" ], [ "Lithuania", "lt", "370" ], [ "Luxembourg", "lu", "352" ], [ "Macau", "mo", "853" ], [ "Madagascar", "mg", "261" ], [ "Malawi", "mw", "265" ], [ "Malaysia", "my", "60" ], [ "Maldives", "mv", "960" ], [ "Mali", "ml", "223" ], [ "Malta", "mt", "356" ], [ "Marshall Islands", "mh", "692" ], [ "Martinique", "mq", "596" ], [ "Mauritania", "mr", "222" ], [ "Mauritius", "mu", "230" ], [ "Mayotte", "yt", "262", 1, [ "269", "639" ] ], [ "Mexico", "mx", "52" ], [ "Micronesia", "fm", "691" ], [ "Moldova", "md", "373" ], [ "Monaco", "mc", "377" ], [ "Mongolia", "mn", "976" ], [ "Montenegro", "me", "382" ], [ "Montserrat", "ms", "1", 16, [ "664" ] ], [ "Morocco", "ma", "212", 0 ], [ "Mozambique", "mz", "258" ], [ "Myanmar (Burma)", "mm", "95" ], [ "Namibia", "na", "264" ], [ "Nauru", "nr", "674" ], [ "Nepal", "np", "977" ], [ "Netherlands", "nl", "31" ], [ "New Caledonia", "nc", "687" ], [ "New Zealand", "nz", "64" ], [ "Nicaragua", "ni", "505" ], [ "Niger", "ne", "227" ], [ "Nigeria", "ng", "234" ], [ "Niue", "nu", "683" ], [ "Norfolk Island", "nf", "672" ], [ "North Korea", "kp", "850" ], [ "North Macedonia", "mk", "389" ], [ "Northern Mariana Islands", "mp", "1", 17, [ "670" ] ], [ "Norway", "no", "47", 0 ], [ "Oman", "om", "968" ], [ "Pakistan", "pk", "92" ], [ "Palau", "pw", "680" ], [ "Palestine", "ps", "970" ], [ "Panama", "pa", "507" ], [ "Papua New Guinea", "pg", "675" ], [ "Paraguay", "py", "595" ], [ "Peru", "pe", "51" ], [ "Philippines", "ph", "63" ], [ "Poland", "pl", "48" ], [ "Portugal", "pt", "351" ], [ "Puerto Rico", "pr", "1", 3, [ "787", "939" ] ], [ "Qatar", "qa", "974" ], [ "Réunion", "re", "262", 0 ], [ "Romania", "ro", "40" ], [ "Russia", "ru", "7", 0 ], [ "Rwanda", "rw", "250" ], [ "Samoa", "ws", "685" ], [ "San Marino", "sm", "378" ], [ "São Tomé & Príncipe", "st", "239" ], [ "Saudi Arabia", "sa", "966" ], [ "Senegal", "sn", "221" ], [ "Serbia", "rs", "381" ], [ "Seychelles", "sc", "248" ], [ "Sierra Leone", "sl", "232" ], [ "Singapore", "sg", "65" ], [ "Sint Maarten", "sx", "1", 21, [ "721" ] ], [ "Slovakia", "sk", "421" ], [ "Slovenia", "si", "386" ], [ "Solomon Islands", "sb", "677" ], [ "Somalia", "so", "252" ], [ "South Africa", "za", "27" ], [ "South Korea", "kr", "82" ], [ "South Sudan", "ss", "211" ], [ "Spain", "es", "34" ], [ "Sri Lanka", "lk", "94" ], [ "St Barthélemy", "bl", "590", 1 ], [ "St Helena", "sh", "290" ], [ "St Kitts & Nevis", "kn", "1", 18, [ "869" ] ], [ "St Lucia", "lc", "1", 19, [ "758" ] ], [ "St Martin", "mf", "590", 2 ], [ "St Pierre & Miquelon", "pm", "508" ], [ "St Vincent & Grenadines", "vc", "1", 20, [ "784" ] ], [ "Sudan", "sd", "249" ], [ "Suriname", "sr", "597" ], [ "Svalbard & Jan Mayen", "sj", "47", 1, [ "79" ] ], [ "Sweden", "se", "46" ], [ "Switzerland", "ch", "41" ], [ "Syria", "sy", "963" ], [ "Taiwan", "tw", "886" ], [ "Tajikistan", "tj", "992" ], [ "Tanzania", "tz", "255" ], [ "Thailand", "th", "66" ], [ "Timor-Leste", "tl", "670" ], [ "Togo", "tg", "228" ], [ "Tokelau", "tk", "690" ], [ "Tonga", "to", "676" ], [ "Trinidad & Tobago", "tt", "1", 22, [ "868" ] ], [ "Tunisia", "tn", "216" ], [ "Turkey", "tr", "90" ], [ "Turkmenistan", "tm", "993" ], [ "Turks & Caicos Islands", "tc", "1", 23, [ "649" ] ], [ "Tuvalu", "tv", "688" ], [ "Uganda", "ug", "256" ], [ "Ukraine", "ua", "380" ], [ "United Arab Emirates", "ae", "971" ], [ "United Kingdom", "gb", "44", 0 ], [ "United States", "us", "1", 0 ], [ "Uruguay", "uy", "598" ], [ "US Virgin Islands", "vi", "1", 24, [ "340" ] ], [ "Uzbekistan", "uz", "998" ], [ "Vanuatu", "vu", "678" ], [ "Vatican City", "va", "39", 1, [ "06698" ] ], [ "Venezuela", "ve", "58" ], [ "Vietnam", "vn", "84" ], [ "Wallis & Futuna", "wf", "681" ], [ "Western Sahara", "eh", "212", 1, [ "5288", "5289" ] ], [ "Yemen", "ye", "967" ], [ "Zambia", "zm", "260" ], [ "Zimbabwe", "zw", "263" ], [ "Åland Islands", "ax", "358", 1, [ "18" ] ] ];
33
- // loop over all of the countries above, restructuring the data to be objects with named keys
34
- for (var i = 0; i < allCountries.length; i++) {
35
- var c = allCountries[i];
36
- allCountries[i] = {
37
- name: c[0],
38
- iso2: c[1],
39
- dialCode: c[2],
40
- priority: c[3] || 0,
41
- areaCodes: c[4] || null,
42
- nodeById: {}
43
- };
44
- }
45
- "use strict";
46
- function ownKeys(object, enumerableOnly) {
47
- var keys = Object.keys(object);
48
- if (Object.getOwnPropertySymbols) {
49
- var symbols = Object.getOwnPropertySymbols(object);
50
- enumerableOnly && (symbols = symbols.filter(function(sym) {
51
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
52
- })), keys.push.apply(keys, symbols);
53
- }
54
- return keys;
55
- }
56
- function _objectSpread(target) {
57
- for (var i = 1; i < arguments.length; i++) {
58
- var source = null != arguments[i] ? arguments[i] : {};
59
- i % 2 ? ownKeys(Object(source), !0).forEach(function(key) {
60
- _defineProperty(target, key, source[key]);
61
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
62
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
63
- });
64
- }
65
- return target;
66
- }
67
- function _defineProperty(obj, key, value) {
68
- key = _toPropertyKey(key);
69
- if (key in obj) {
70
- Object.defineProperty(obj, key, {
71
- value: value,
72
- enumerable: true,
73
- configurable: true,
74
- writable: true
75
- });
76
- } else {
77
- obj[key] = value;
78
- }
79
- return obj;
80
- }
81
- function _slicedToArray(arr, i) {
82
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
83
- }
84
- function _nonIterableRest() {
85
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
86
- }
87
- function _unsupportedIterableToArray(o, minLen) {
88
- if (!o) return;
89
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
90
- var n = Object.prototype.toString.call(o).slice(8, -1);
91
- if (n === "Object" && o.constructor) n = o.constructor.name;
92
- if (n === "Map" || n === "Set") return Array.from(o);
93
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
94
- }
95
- function _arrayLikeToArray(arr, len) {
96
- if (len == null || len > arr.length) len = arr.length;
97
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
98
- return arr2;
99
- }
100
- function _iterableToArrayLimit(arr, i) {
101
- var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
102
- if (null != _i) {
103
- var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1;
104
- try {
105
- if (_x = (_i = _i.call(arr)).next, 0 === i) {
106
- if (Object(_i) !== _i) return;
107
- _n = !1;
108
- } else for (;!(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) ;
109
- } catch (err) {
110
- _d = !0, _e = err;
111
- } finally {
112
- try {
113
- if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
114
- } finally {
115
- if (_d) throw _e;
116
- }
117
- }
118
- return _arr;
119
- }
120
- }
121
- function _arrayWithHoles(arr) {
122
- if (Array.isArray(arr)) return arr;
123
- }
124
- function _classCallCheck(instance, Constructor) {
125
- if (!(instance instanceof Constructor)) {
126
- throw new TypeError("Cannot call a class as a function");
127
- }
128
- }
129
- function _defineProperties(target, props) {
130
- for (var i = 0; i < props.length; i++) {
131
- var descriptor = props[i];
132
- descriptor.enumerable = descriptor.enumerable || false;
133
- descriptor.configurable = true;
134
- if ("value" in descriptor) descriptor.writable = true;
135
- Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
136
- }
137
- }
138
- function _createClass(Constructor, protoProps, staticProps) {
139
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
140
- if (staticProps) _defineProperties(Constructor, staticProps);
141
- Object.defineProperty(Constructor, "prototype", {
142
- writable: false
143
- });
144
- return Constructor;
145
- }
146
- function _toPropertyKey(arg) {
147
- var key = _toPrimitive(arg, "string");
148
- return typeof key === "symbol" ? key : String(key);
149
- }
150
- function _toPrimitive(input, hint) {
151
- if (typeof input !== "object" || input === null) return input;
152
- var prim = input[Symbol.toPrimitive];
153
- if (prim !== undefined) {
154
- var res = prim.call(input, hint || "default");
155
- if (typeof res !== "object") return res;
156
- throw new TypeError("@@toPrimitive must return a primitive value.");
157
- }
158
- return (hint === "string" ? String : Number)(input);
159
- }
160
- var intlTelInputGlobals = {
161
- getInstance: function getInstance(input) {
162
- var id = input.getAttribute("data-intl-tel-input-id");
163
- return window.intlTelInputGlobals.instances[id];
164
- },
165
- instances: {},
166
- // using a global like this allows us to mock it in the tests
167
- documentReady: function documentReady() {
168
- return document.readyState === "complete";
169
- }
170
- };
171
- if (typeof window === "object") {
172
- window.intlTelInputGlobals = intlTelInputGlobals;
173
- }
174
- // these vars persist through all instances of the plugin
175
- var id = 0;
176
- var defaults = {
177
- // whether or not to allow the dropdown
178
- allowDropdown: true,
179
- // add a placeholder in the input with an example number for the selected country
180
- autoPlaceholder: "polite",
181
- // add a country search input at the top of the dropdown
182
- countrySearch: true,
183
- // modify the parentClass
184
- containerClass: "",
185
- // modify the auto placeholder
186
- customPlaceholder: null,
187
- // append menu to specified element
188
- dropdownContainer: null,
189
- // don't display these countries
190
- excludeCountries: [],
191
- // fix the dropdown width to the input width (rather than being as wide as the longest country name)
192
- fixDropdownWidth: true,
193
- // format the number as the user types
194
- formatAsYouType: true,
195
- // format the input value during initialisation and on setNumber
196
- formatOnDisplay: true,
197
- // geoIp lookup function
198
- geoIpLookup: null,
199
- // inject a hidden input with the name returned from this function, and on submit, populate it with the result of getNumber
200
- hiddenInput: null,
201
- // internationalise the plugin text e.g. search input placeholder, country names
202
- i18n: {},
203
- // initial country
204
- initialCountry: "",
205
- // national vs international formatting for numbers e.g. placeholders and displaying existing numbers
206
- nationalMode: true,
207
- // display only these countries
208
- onlyCountries: [],
209
- // number type to use for placeholders
210
- placeholderNumberType: "MOBILE",
211
- // the countries at the top of the list
212
- preferredCountries: [],
213
- // option to hide the flags - must be used with showSelectedDialCode, or allowDropdown=false
214
- showFlags: true,
215
- // display the international dial code next to the selected flag
216
- showSelectedDialCode: false,
217
- // only allow certain chars e.g. a plus followed by numeric digits, and cap at max valid length
218
- strictMode: false,
219
- // use full screen popup instead of dropdown for country list
220
- useFullscreenPopup: typeof navigator !== "undefined" && typeof window !== "undefined" ? // we cannot just test screen size as some smartphones/website meta tags will report desktop
221
- // resolutions
222
- // Note: to target Android Mobiles (and not Tablets), we must find 'Android' and 'Mobile'
223
- /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || window.innerWidth <= 500 : false,
224
- // specify the path to the libphonenumber script to enable validation/formatting
225
- utilsScript: ""
226
- };
227
- // https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#Non-geographic_area_codes
228
- var regionlessNanpNumbers = [ "800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889" ];
229
- // run a method on each instance of the plugin
230
- var forEachInstance = function forEachInstance(method) {
231
- var instances = window.intlTelInputGlobals.instances;
232
- Object.values(instances).forEach(function(instance) {
233
- return instance[method]();
234
- });
235
- };
236
- // this is our plugin class that we will create an instance of
237
- // eslint-disable-next-line no-unused-vars
238
- var Iti = /*#__PURE__*/ function() {
239
- function Iti(input) {
240
- var customOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
241
- _classCallCheck(this, Iti);
242
- this.id = id++;
243
- this.telInput = input;
244
- this.activeItem = null;
245
- this.highlightedItem = null;
246
- // process specified options / defaults
247
- this.options = Object.assign({}, defaults, customOptions);
248
- this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder"));
249
- }
250
- _createClass(Iti, [ {
251
- key: "_init",
252
- value: function _init() {
253
- var _this = this;
254
- // if showing fullscreen popup, do not fix the width
255
- if (this.options.useFullscreenPopup) {
256
- this.options.fixDropdownWidth = false;
257
- }
258
- // when search enabled, we must fix the width else it would change with different results
259
- if (this.options.countrySearch && !this.options.useFullscreenPopup) {
260
- this.options.fixDropdownWidth = true;
261
- }
262
- // force showFlags=true if there's a dropdown and we're not displaying the dial code,
263
- // as otherwise you just have a down arrow on it's own which doesn't make sense
264
- var forceShowFlags = this.options.allowDropdown && !this.options.showSelectedDialCode;
265
- if (!this.options.showFlags && forceShowFlags) {
266
- this.options.showFlags = true;
267
- }
268
- // on mobile, we want a full screen dropdown, so we must append it to the body
269
- if (this.options.useFullscreenPopup && !this.options.dropdownContainer) {
270
- this.options.dropdownContainer = document.body;
271
- }
272
- // check if input has one parent with RTL
273
- this.isRTL = !!this.telInput.closest("[dir=rtl]");
274
- // these promises get resolved when their individual requests complete
275
- // this way the dev can do something like iti.promise.then(...) to know when all requests are
276
- // complete
277
- var autoCountryPromise = new Promise(function(resolve, reject) {
278
- _this.resolveAutoCountryPromise = resolve;
279
- _this.rejectAutoCountryPromise = reject;
280
- });
281
- var utilsScriptPromise = new Promise(function(resolve, reject) {
282
- _this.resolveUtilsScriptPromise = resolve;
283
- _this.rejectUtilsScriptPromise = reject;
284
- });
285
- this.promise = Promise.all([ autoCountryPromise, utilsScriptPromise ]);
286
- // in various situations there could be no country selected initially, but we need to be able
287
- // to assume this variable exists
288
- this.selectedCountryData = {};
289
- // process all the data: onlyCountries, excludeCountries, preferredCountries etc
290
- this._processCountryData();
291
- // generate the markup
292
- this._generateMarkup();
293
- // set the initial state of the input value and the selected flag
294
- this._setInitialState();
295
- // start all of the event listeners: input keydown, selectedFlag click
296
- this._initListeners();
297
- // utils script, and auto country
298
- this._initRequests();
299
- }
300
- }, {
301
- key: "_processCountryData",
302
- value: function _processCountryData() {
303
- // process onlyCountries or excludeCountries array if present
304
- this._processAllCountries();
305
- // generate this.dialCodes and this.dialCodeToIso2Map
306
- this._processDialCodes();
307
- // process the preferredCountries
308
- this._processPreferredCountries();
309
- // translate country names according to i18n option
310
- this._translateCountryNames();
311
- // sort countries by name
312
- if (this.options.onlyCountries.length || this.options.i18n) {
313
- this.countries.sort(this._countryNameSort);
314
- }
315
- }
316
- }, {
317
- key: "_addToDialCodeMap",
318
- value: function _addToDialCodeMap(iso2, dialCode, priority) {
319
- if (dialCode.length > this.dialCodeMaxLen) {
320
- this.dialCodeMaxLen = dialCode.length;
321
- }
322
- if (!this.dialCodeToIso2Map.hasOwnProperty(dialCode)) {
323
- this.dialCodeToIso2Map[dialCode] = [];
324
- }
325
- // bail if we already have this country for this dialCode
326
- for (var i = 0; i < this.dialCodeToIso2Map[dialCode].length; i++) {
327
- if (this.dialCodeToIso2Map[dialCode][i] === iso2) {
328
- return;
329
- }
330
- }
331
- // check for undefined as 0 is falsy
332
- var index = priority !== undefined ? priority : this.dialCodeToIso2Map[dialCode].length;
333
- this.dialCodeToIso2Map[dialCode][index] = iso2;
334
- }
335
- }, {
336
- key: "_processAllCountries",
337
- value: function _processAllCountries() {
338
- if (this.options.onlyCountries.length) {
339
- var lowerCaseOnlyCountries = this.options.onlyCountries.map(function(country) {
340
- return country.toLowerCase();
341
- });
342
- this.countries = allCountries.filter(function(country) {
343
- return lowerCaseOnlyCountries.indexOf(country.iso2) > -1;
344
- });
345
- } else if (this.options.excludeCountries.length) {
346
- var lowerCaseExcludeCountries = this.options.excludeCountries.map(function(country) {
347
- return country.toLowerCase();
348
- });
349
- this.countries = allCountries.filter(function(country) {
350
- return lowerCaseExcludeCountries.indexOf(country.iso2) === -1;
351
- });
352
- } else {
353
- this.countries = allCountries;
354
- }
355
- }
356
- }, {
357
- key: "_translateCountryNames",
358
- value: function _translateCountryNames() {
359
- for (var i = 0; i < this.countries.length; i++) {
360
- var iso2 = this.countries[i].iso2.toLowerCase();
361
- if (this.options.i18n.hasOwnProperty(iso2)) {
362
- this.countries[i].name = this.options.i18n[iso2];
363
- }
364
- }
365
- }
366
- }, {
367
- key: "_countryNameSort",
368
- value: function _countryNameSort(a, b) {
369
- if (a.name < b.name) {
370
- return -1;
371
- }
372
- if (a.name > b.name) {
373
- return 1;
374
- }
375
- return 0;
376
- }
377
- }, {
378
- key: "_processDialCodes",
379
- value: function _processDialCodes() {
380
- // here we store just dial codes, where the key is the dial code, and the value is true
381
- // e.g. { 1: true, 7: true, 20: true, ... }
382
- this.dialCodes = {};
383
- this.dialCodeMaxLen = 0;
384
- // here we map dialCodes (inc both dialCode and dialCode+areaCode) to iso2 codes
385
- /* e.g.
386
- * {
387
- * 1: [ 'us', 'ca', ... ], # all NANP countries
388
- * 12: [ 'us', 'ca', ... ], # subset of NANP countries
389
- * 120: [ 'us', 'ca' ], # just US and Canada
390
- * 1204: [ 'ca' ], # only Canada
391
- * ...
392
- * }
393
- */
394
- this.dialCodeToIso2Map = {};
395
- // first: add dial codes
396
- for (var i = 0; i < this.countries.length; i++) {
397
- var c = this.countries[i];
398
- if (!this.dialCodes[c.dialCode]) {
399
- this.dialCodes[c.dialCode] = true;
400
- }
401
- this._addToDialCodeMap(c.iso2, c.dialCode, c.priority);
402
- }
403
- // next: add area codes
404
- // this is a second loop over countries, to make sure we have all of the "root" countries
405
- // already in the map, so that we can access them, as each time we add an area code substring
406
- // to the map, we also need to include the "root" country's code, as that also matches
407
- for (var _i = 0; _i < this.countries.length; _i++) {
408
- var _c = this.countries[_i];
409
- // area codes
410
- if (_c.areaCodes) {
411
- var rootIso2Code = this.dialCodeToIso2Map[_c.dialCode][0];
412
- // for each area code
413
- for (var j = 0; j < _c.areaCodes.length; j++) {
414
- var areaCode = _c.areaCodes[j];
415
- // for each digit in the area code to add all partial matches as well
416
- for (var k = 1; k < areaCode.length; k++) {
417
- var partialDialCode = _c.dialCode + areaCode.substr(0, k);
418
- // start with the root country, as that also matches this dial code
419
- this._addToDialCodeMap(rootIso2Code, partialDialCode);
420
- this._addToDialCodeMap(_c.iso2, partialDialCode);
421
- }
422
- // add the full area code
423
- this._addToDialCodeMap(_c.iso2, _c.dialCode + areaCode);
424
- }
425
- }
426
- }
427
- }
428
- }, {
429
- key: "_processPreferredCountries",
430
- value: function _processPreferredCountries() {
431
- this.preferredCountries = [];
432
- for (var i = 0; i < this.options.preferredCountries.length; i++) {
433
- var iso2 = this.options.preferredCountries[i].toLowerCase();
434
- var countryData = this._getCountryData(iso2, true);
435
- if (countryData) {
436
- this.preferredCountries.push(countryData);
437
- }
438
- }
439
- }
440
- }, {
441
- key: "_createEl",
442
- value: function _createEl(name, attrs, container) {
443
- var el = document.createElement(name);
444
- if (attrs) {
445
- Object.entries(attrs).forEach(function(_ref) {
446
- var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1];
447
- return el.setAttribute(key, value);
448
- });
449
- }
450
- if (container) {
451
- container.appendChild(el);
452
- }
453
- return el;
454
- }
455
- }, {
456
- key: "_generateMarkup",
457
- value: function _generateMarkup() {
458
- this.telInput.classList.add("iti__tel-input");
459
- // if autocomplete does not exist on the element and its form, then
460
- // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can
461
- // easily put the plugin in an inconsistent state e.g. the wrong flag selected for the
462
- // autocompleted number, which on submit could mean wrong number is saved
463
- if (!this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete"))) {
464
- this.telInput.setAttribute("autocomplete", "off");
465
- }
466
- var _this$options = this.options, allowDropdown = _this$options.allowDropdown, showSelectedDialCode = _this$options.showSelectedDialCode, showFlags = _this$options.showFlags, containerClass = _this$options.containerClass, hiddenInput = _this$options.hiddenInput, dropdownContainer = _this$options.dropdownContainer, fixDropdownWidth = _this$options.fixDropdownWidth, useFullscreenPopup = _this$options.useFullscreenPopup, countrySearch = _this$options.countrySearch, i18n = _this$options.i18n;
467
- // containers (mostly for positioning)
468
- var parentClass = "iti";
469
- if (allowDropdown) {
470
- parentClass += " iti--allow-dropdown";
471
- }
472
- if (showSelectedDialCode) {
473
- parentClass += " iti--show-selected-dial-code";
474
- }
475
- if (showFlags) {
476
- parentClass += " iti--show-flags";
477
- }
478
- if (containerClass) {
479
- parentClass += " ".concat(containerClass);
480
- }
481
- if (!useFullscreenPopup) {
482
- parentClass += " iti--inline-dropdown";
483
- }
484
- var wrapper = this._createEl("div", {
485
- "class": parentClass
486
- });
487
- this.telInput.parentNode.insertBefore(wrapper, this.telInput);
488
- // if we're showing flags or dial codes, we need the flags container etc
489
- if (showFlags || showSelectedDialCode) {
490
- this.flagsContainer = this._createEl("div", {
491
- "class": "iti__flag-container"
492
- }, wrapper);
493
- // selected flag (displayed on left of input while allowDropdown is enabled, otherwise to right)
494
- // when countrySearch disabled: using Aria tags for "Select-Only Combobox Example"
495
- // https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/
496
- this.selectedFlag = this._createEl("div", _objectSpread({
497
- "class": "iti__selected-flag"
498
- }, allowDropdown && _objectSpread({
499
- role: "button",
500
- "aria-expanded": "false",
501
- "aria-label": this.options.i18n.selectedCountryAriaLabel || "Selected country",
502
- "aria-haspopup": countrySearch ? "true" : "listbox",
503
- "aria-controls": countrySearch ? "iti-".concat(this.id, "__dropdown-content") : "iti-".concat(this.id, "__country-listbox")
504
- }, countrySearch || {
505
- role: "combobox"
506
- })), this.flagsContainer);
507
- // we now include the selected flag element even when showFlags is disabled,
508
- // as need to show globe icon for showSelectedDialCode empty state
509
- this.selectedFlagInner = this._createEl("div", null, this.selectedFlag);
510
- this.selectedFlagA11yText = this._createEl("span", {
511
- "class": "iti__a11y-text"
512
- }, this.selectedFlagInner);
513
- }
514
- wrapper.appendChild(this.telInput);
515
- if (this.selectedFlag && this.telInput.disabled) {
516
- this.selectedFlag.setAttribute("aria-disabled", "true");
517
- }
518
- if (showSelectedDialCode) {
519
- this.selectedDialCode = this._createEl("div", {
520
- "class": "iti__selected-dial-code"
521
- }, this.selectedFlag);
522
- }
523
- if (allowDropdown) {
524
- if (!this.telInput.disabled) {
525
- // make element focusable and tab navigable
526
- this.selectedFlag.setAttribute("tabindex", "0");
527
- }
528
- this.dropdownArrow = this._createEl("div", {
529
- "class": "iti__arrow",
530
- "aria-hidden": "true"
531
- }, this.selectedFlag);
532
- var extraClasses = fixDropdownWidth ? "" : "iti--flexible-dropdown-width";
533
- this.dropdownContent = this._createEl("div", {
534
- id: "iti-".concat(this.id, "__dropdown-content"),
535
- "class": "iti__dropdown-content iti__hide ".concat(extraClasses)
536
- });
537
- if (countrySearch) {
538
- this.searchInput = this._createEl("input", {
539
- type: "text",
540
- "class": "iti__search-input",
541
- placeholder: i18n.searchPlaceholder || "Search",
542
- role: "combobox",
543
- "aria-expanded": "true",
544
- "aria-label": i18n.searchPlaceholder || "Search",
545
- "aria-controls": "iti-".concat(this.id, "__country-listbox"),
546
- "aria-autocomplete": "list",
547
- autocomplete: "off"
548
- }, this.dropdownContent);
549
- this.searchResultsA11yText = this._createEl("span", {
550
- "class": "iti__a11y-text"
551
- }, this.dropdownContent);
552
- }
553
- // country list: preferred countries, then divider, then all countries
554
- this.countryList = this._createEl("ul", {
555
- "class": "iti__country-list",
556
- id: "iti-".concat(this.id, "__country-listbox"),
557
- role: "listbox",
558
- "aria-label": i18n.countryListAriaLabel || "List of countries"
559
- }, this.dropdownContent);
560
- if (this.preferredCountries.length && !countrySearch) {
561
- this._appendListItems(this.preferredCountries, "iti__preferred", true);
562
- this._createEl("li", {
563
- "class": "iti__divider",
564
- "aria-hidden": "true"
565
- }, this.countryList);
566
- }
567
- this._appendListItems(this.countries, "iti__standard");
568
- if (countrySearch) {
569
- this._updateSearchResultsText();
570
- }
571
- // create dropdownContainer markup
572
- if (dropdownContainer) {
573
- var dropdownClasses = "iti iti--container";
574
- if (useFullscreenPopup) {
575
- dropdownClasses += " iti--fullscreen-popup";
576
- } else {
577
- dropdownClasses += " iti--inline-dropdown";
578
- }
579
- if (countrySearch) {
580
- dropdownClasses += " iti--country-search";
581
- }
582
- this.dropdown = this._createEl("div", {
583
- "class": dropdownClasses
584
- });
585
- this.dropdown.appendChild(this.dropdownContent);
586
- } else {
587
- this.flagsContainer.appendChild(this.dropdownContent);
588
- }
589
- }
590
- if (hiddenInput) {
591
- var telInputName = this.telInput.getAttribute("name");
592
- var names = hiddenInput(telInputName);
593
- if (names.phone) {
594
- // Create hidden input for the full international number
595
- this.hiddenInput = this._createEl("input", {
596
- type: "hidden",
597
- name: names.phone
598
- });
599
- wrapper.appendChild(this.hiddenInput);
600
- }
601
- if (names.country) {
602
- // Create hidden input for the selected country iso2 code
603
- this.hiddenInputCountry = this._createEl("input", {
604
- type: "hidden",
605
- name: names.country
606
- });
607
- wrapper.appendChild(this.hiddenInputCountry);
608
- }
609
- }
610
- }
611
- }, {
612
- key: "_appendListItems",
613
- value: function _appendListItems(countries, className, preferred) {
614
- for (var i = 0; i < countries.length; i++) {
615
- var c = countries[i];
616
- var idSuffix = preferred ? "-preferred" : "";
617
- var listItem = this._createEl("li", {
618
- id: "iti-".concat(this.id, "__item-").concat(c.iso2).concat(idSuffix),
619
- "class": "iti__country ".concat(className),
620
- tabindex: "-1",
621
- role: "option",
622
- "data-dial-code": c.dialCode,
623
- "data-country-code": c.iso2,
624
- "aria-selected": "false"
625
- }, this.countryList);
626
- // store this for later use e.g. country search filtering
627
- c.nodeById[this.id] = listItem;
628
- var content = "";
629
- // add the flag
630
- if (this.options.showFlags) {
631
- content += "<div class='iti__flag-box'><div class='iti__flag iti__".concat(c.iso2, "'></div></div>");
632
- }
633
- // and the country name and dial code
634
- content += "<span class='iti__country-name'>".concat(c.name, "</span>");
635
- content += "<span class='iti__dial-code'>+".concat(c.dialCode, "</span>");
636
- listItem.insertAdjacentHTML("beforeend", content);
637
- }
638
- }
639
- }, {
640
- key: "_setInitialState",
641
- value: function _setInitialState() {
642
- var overrideAutoCountry = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
643
- // fix firefox bug: when first load page (with input with value set to number with intl dial
644
- // code) and initialising plugin removes the dial code from the input, then refresh page,
645
- // and we try to init plugin again but this time on number without dial code so get grey flag
646
- var attributeValue = this.telInput.getAttribute("value");
647
- var inputValue = this.telInput.value;
648
- var useAttribute = attributeValue && attributeValue.charAt(0) === "+" && (!inputValue || inputValue.charAt(0) !== "+");
649
- var val = useAttribute ? attributeValue : inputValue;
650
- var dialCode = this._getDialCode(val);
651
- var isRegionlessNanp = this._isRegionlessNanp(val);
652
- var initialCountry = this.options.initialCountry;
653
- // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the
654
- // flag, else fall back to the default country
655
- if (dialCode && !isRegionlessNanp) {
656
- this._updateFlagFromNumber(val);
657
- } else if (initialCountry !== "auto" || overrideAutoCountry) {
658
- var lowerInitialCountry = initialCountry ? initialCountry.toLowerCase() : "";
659
- var isValidInitialCountry = lowerInitialCountry && this._getCountryData(lowerInitialCountry, true);
660
- // see if we should select a flag
661
- if (isValidInitialCountry) {
662
- this._setCountry(lowerInitialCountry);
663
- } else {
664
- if (dialCode && isRegionlessNanp) {
665
- // has intl dial code, is regionless nanp, and no initialCountry, so default to US
666
- this._setCountry("us");
667
- } else {
668
- // display the empty state (globe icon)
669
- this._setCountry();
670
- }
671
- }
672
- }
673
- // NOTE: if initialCountry is set to auto, that will be handled separately
674
- // format - note this wont be run after _updateDialCode as that's only called if no val
675
- if (val) {
676
- this._updateValFromNumber(val);
677
- }
678
- }
679
- }, {
680
- key: "_initListeners",
681
- value: function _initListeners() {
682
- this._initTelInputListeners();
683
- if (this.options.allowDropdown) {
684
- this._initDropdownListeners();
685
- }
686
- if ((this.hiddenInput || this.hiddenInputCountry) && this.telInput.form) {
687
- this._initHiddenInputListener();
688
- }
689
- }
690
- }, {
691
- key: "_initHiddenInputListener",
692
- value: function _initHiddenInputListener() {
693
- var _this2 = this;
694
- this._handleHiddenInputSubmit = function() {
695
- if (_this2.hiddenInput) {
696
- _this2.hiddenInput.value = _this2.getNumber();
697
- }
698
- if (_this2.hiddenInputCountry) {
699
- _this2.hiddenInputCountry.value = _this2.getSelectedCountryData().iso2;
700
- }
701
- };
702
- this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit);
703
- }
704
- }, {
705
- key: "_initDropdownListeners",
706
- value: function _initDropdownListeners() {
707
- var _this3 = this;
708
- // hack for input nested inside label (which is valid markup): clicking the selected-flag to
709
- // open the dropdown would then automatically trigger a 2nd click on the input which would
710
- // close it again
711
- this._handleLabelClick = function(e) {
712
- // if the dropdown is closed, then focus the input, else ignore the click
713
- if (_this3.dropdownContent.classList.contains("iti__hide")) {
714
- _this3.telInput.focus();
715
- } else {
716
- e.preventDefault();
717
- }
718
- };
719
- var label = this.telInput.closest("label");
720
- if (label) {
721
- label.addEventListener("click", this._handleLabelClick);
722
- }
723
- // toggle country dropdown on click
724
- this._handleClickSelectedFlag = function() {
725
- // only intercept this event if we're opening the dropdown
726
- // else let it bubble up to the top ("click-off-to-close" listener)
727
- // we cannot just stopPropagation as it may be needed to close another instance
728
- if (_this3.dropdownContent.classList.contains("iti__hide") && !_this3.telInput.disabled && !_this3.telInput.readOnly) {
729
- _this3._openDropdown();
730
- }
731
- };
732
- this.selectedFlag.addEventListener("click", this._handleClickSelectedFlag);
733
- // open dropdown if selected flag is focused and they press up/down/space/enter
734
- this._handleFlagsContainerKeydown = function(e) {
735
- var isDropdownHidden = _this3.dropdownContent.classList.contains("iti__hide");
736
- if (isDropdownHidden && [ "ArrowUp", "ArrowDown", " ", "Enter" ].includes(e.key)) {
737
- // prevent form from being submitted if "ENTER" was pressed
738
- e.preventDefault();
739
- // prevent event from being handled again by document
740
- e.stopPropagation();
741
- _this3._openDropdown();
742
- }
743
- // allow navigation from dropdown to input on TAB
744
- if (e.key === "Tab") {
745
- _this3._closeDropdown();
746
- }
747
- };
748
- this.flagsContainer.addEventListener("keydown", this._handleFlagsContainerKeydown);
749
- }
750
- }, {
751
- key: "_initRequests",
752
- value: function _initRequests() {
753
- var _this4 = this;
754
- // if the user has specified the path to the utils script, fetch it on window.load, else resolve
755
- if (this.options.utilsScript && !window.intlTelInputUtils) {
756
- // if the plugin is being initialised after the window.load event has already been fired
757
- if (window.intlTelInputGlobals.documentReady()) {
758
- window.intlTelInputGlobals.loadUtils(this.options.utilsScript);
759
- } else {
760
- // wait until the load event so we don't block any other requests e.g. the flags image
761
- window.addEventListener("load", function() {
762
- window.intlTelInputGlobals.loadUtils(_this4.options.utilsScript);
763
- });
764
- }
765
- } else {
766
- this.resolveUtilsScriptPromise();
767
- }
768
- // dont bother with IP lookup if we already have a selected country
769
- if (this.options.initialCountry === "auto" && !this.selectedCountryData.iso2) {
770
- this._loadAutoCountry();
771
- } else {
772
- this.resolveAutoCountryPromise();
773
- }
774
- }
775
- }, {
776
- key: "_loadAutoCountry",
777
- value: function _loadAutoCountry() {
778
- var _this5 = this;
779
- // 3 options:
780
- // 1) already loaded (we're done)
781
- // 2) not already started loading (start)
782
- // 3) already started loading (do nothing - just wait for loading callback to fire)
783
- if (window.intlTelInputGlobals.autoCountry) {
784
- this.handleAutoCountry();
785
- } else if (!window.intlTelInputGlobals.startedLoadingAutoCountry) {
786
- // don't do this twice!
787
- window.intlTelInputGlobals.startedLoadingAutoCountry = true;
788
- if (typeof this.options.geoIpLookup === "function") {
789
- this.options.geoIpLookup(function() {
790
- var iso2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
791
- var iso2Lower = iso2.toLowerCase();
792
- var isValidIso2 = iso2Lower && _this5._getCountryData(iso2Lower, true);
793
- if (isValidIso2) {
794
- window.intlTelInputGlobals.autoCountry = iso2Lower;
795
- // tell all instances the auto country is ready
796
- // TODO: this should just be the current instances
797
- // UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight
798
- // away (e.g. if they have already done the geo ip lookup somewhere else). Using
799
- // setTimeout means that the current thread of execution will finish before executing
800
- // this, which allows the plugin to finish initialising.
801
- setTimeout(function() {
802
- return forEachInstance("handleAutoCountry");
803
- });
804
- } else {
805
- _this5._setInitialState(true);
806
- forEachInstance("rejectAutoCountryPromise");
807
- }
808
- }, function() {
809
- return forEachInstance("rejectAutoCountryPromise");
810
- });
811
- }
812
- }
813
- }
814
- }, {
815
- key: "_initTelInputListeners",
816
- value: function _initTelInputListeners() {
817
- var _this6 = this;
818
- var _this$options2 = this.options, strictMode = _this$options2.strictMode, formatAsYouType = _this$options2.formatAsYouType;
819
- var userOverrideFormatting = false;
820
- // update flag on input event
821
- this._handleInputEvent = function(e) {
822
- if (_this6._updateFlagFromNumber(_this6.telInput.value)) {
823
- _this6._triggerCountryChange();
824
- }
825
- // if user types their own formatting char (not a plus or a numeric), or they paste something, then set the override
826
- var isFormattingChar = e && e.data && /[^+0-9]/.test(e.data);
827
- var isPaste = e && e.inputType === "insertFromPaste" && _this6.telInput.value;
828
- if (isFormattingChar || isPaste && !strictMode) {
829
- userOverrideFormatting = true;
830
- } else if (!/[^+0-9]/.test(_this6.telInput.value)) {
831
- userOverrideFormatting = false;
832
- }
833
- // handle FAYT, unless userOverrideFormatting
834
- if (formatAsYouType && !userOverrideFormatting) {
835
- // maintain caret position after reformatting
836
- var currentCaretPos = _this6.telInput.selectionStart;
837
- var valueBeforeCaret = _this6.telInput.value.substring(0, currentCaretPos);
838
- var relevantCharsBeforeCaret = valueBeforeCaret.replace(/[^+0-9]/g, "").length;
839
- var isDeleteForwards = e && e.inputType === "deleteContentForward";
840
- var formattedValue = _this6._formatNumberAsYouType();
841
- var newCaretPos = _this6._translateCursorPosition(relevantCharsBeforeCaret, formattedValue, currentCaretPos, isDeleteForwards);
842
- _this6.telInput.value = formattedValue;
843
- _this6.telInput.setSelectionRange(newCaretPos, newCaretPos);
844
- }
845
- };
846
- // this handles individual key presses as well as cut/paste events
847
- // the advantage of the "input" event over "keyup" etc is that "input" only fires when the value changes,
848
- // whereas "keyup" fires even for shift key, arrow key presses etc
849
- this.telInput.addEventListener("input", this._handleInputEvent);
850
- if (strictMode) {
851
- this._handleKeydownEvent = function(e) {
852
- // only ignore actual character presses, rather than ctrl, alt, shift, command, arrow keys, delete/backspace, cut/copy/paste etc
853
- if (e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
854
- var isInitialPlus = _this6.telInput.selectionStart === 0 && e.key === "+";
855
- var isNumeric = /^[0-9]$/.test(e.key);
856
- var isAllowedChar = isInitialPlus || isNumeric;
857
- var fullNumber = _this6._getFullNumber();
858
- var coreNumber = intlTelInputUtils.getCoreNumber(fullNumber, _this6.selectedCountryData.iso2);
859
- var hasReachedMaxLength = _this6.maxCoreNumberLength && coreNumber.length >= _this6.maxCoreNumberLength;
860
- if (!isAllowedChar || hasReachedMaxLength) {
861
- e.preventDefault();
862
- }
863
- }
864
- };
865
- this.telInput.addEventListener("keydown", this._handleKeydownEvent);
866
- }
867
- }
868
- }, {
869
- key: "_translateCursorPosition",
870
- value: function _translateCursorPosition(relevantChars, formattedValue, prevCaretPos, isDeleteForwards) {
871
- // if the first char is a formatting char, and they backspace delete it:
872
- // cursor should stay at the start (pos 0), rather than stick to the first digit (pos 1)
873
- if (prevCaretPos === 0 && !isDeleteForwards) {
874
- return 0;
875
- }
876
- var count = 0;
877
- for (var i = 0; i < formattedValue.length; i++) {
878
- if (/[+0-9]/.test(formattedValue[i])) {
879
- count++;
880
- }
881
- // normal case: stop when you hit the right number of relevant chars
882
- // (cursor will be just after the final relevant char)
883
- if (count === relevantChars && !isDeleteForwards) {
884
- return i + 1;
885
- }
886
- // spacial case: delete forwards (fn + delete on a mac):
887
- // wait until hit one extra relevant char, and put the cursor just before it (after any formatting chars)
888
- if (isDeleteForwards && count === relevantChars + 1) {
889
- return i;
890
- }
891
- }
892
- return formattedValue.length;
893
- }
894
- }, {
895
- key: "_cap",
896
- value: function _cap(number) {
897
- var max = this.telInput.getAttribute("maxlength");
898
- return max && number.length > max ? number.substr(0, max) : number;
899
- }
900
- }, {
901
- key: "_removeEmptyDialCode",
902
- value: function _removeEmptyDialCode() {
903
- if (this.telInput.value.charAt(0) === "+") {
904
- var numeric = this._getNumeric(this.telInput.value);
905
- // if just a plus, or if just a dial code
906
- if (!numeric || this.selectedCountryData.dialCode === numeric) {
907
- this.telInput.value = "";
908
- }
909
- }
910
- }
911
- }, {
912
- key: "_getNumeric",
913
- value: function _getNumeric(s) {
914
- return s.replace(/\D/g, "");
915
- }
916
- }, {
917
- key: "_trigger",
918
- value: function _trigger(name) {
919
- var e = new Event(name, {
920
- bubbles: true,
921
- cancelable: true
922
- });
923
- this.telInput.dispatchEvent(e);
924
- }
925
- }, {
926
- key: "_openDropdown",
927
- value: function _openDropdown() {
928
- var _this$options3 = this.options, fixDropdownWidth = _this$options3.fixDropdownWidth, countrySearch = _this$options3.countrySearch;
929
- if (fixDropdownWidth) {
930
- this.dropdownContent.style.width = "".concat(this.telInput.offsetWidth, "px");
931
- }
932
- this.dropdownContent.classList.remove("iti__hide");
933
- this.selectedFlag.setAttribute("aria-expanded", "true");
934
- this._setDropdownPosition();
935
- // if we have previously selected a country (and countrySearch is disabled), then highlight that item and scroll to it
936
- // else highlight the first item and scroll to top (even if countrySearch is disabled e.g. on init, showing globe icon)
937
- if (this.activeItem && !countrySearch) {
938
- // update highlighting and scroll to active list item
939
- this._highlightListItem(this.activeItem, false);
940
- this._scrollTo(this.activeItem, true);
941
- } else {
942
- // start by highlighting the first item in the list
943
- var firstElementChild = this.countryList.firstElementChild;
944
- if (firstElementChild) {
945
- this._highlightListItem(firstElementChild, false);
946
- this.countryList.scrollTop = 0;
947
- }
948
- if (countrySearch) {
949
- this.searchInput.focus();
950
- }
951
- }
952
- // bind all the dropdown-related listeners: mouseover, click, click-off, keydown
953
- this._bindDropdownListeners();
954
- // update the arrow
955
- this.dropdownArrow.classList.add("iti__arrow--up");
956
- this._trigger("open:countrydropdown");
957
- }
958
- }, {
959
- key: "_toggleClass",
960
- value: function _toggleClass(el, className, shouldHaveClass) {
961
- if (shouldHaveClass && !el.classList.contains(className)) {
962
- el.classList.add(className);
963
- } else if (!shouldHaveClass && el.classList.contains(className)) {
964
- el.classList.remove(className);
965
- }
966
- }
967
- }, {
968
- key: "_setDropdownPosition",
969
- value: function _setDropdownPosition() {
970
- var _this7 = this;
971
- if (this.options.dropdownContainer) {
972
- this.options.dropdownContainer.appendChild(this.dropdown);
973
- }
974
- if (!this.options.useFullscreenPopup) {
975
- var pos = this.telInput.getBoundingClientRect();
976
- // windowTop from https://stackoverflow.com/a/14384091/217866
977
- var windowTop = document.documentElement.scrollTop;
978
- var inputTop = pos.top + windowTop;
979
- var dropdownHeight = this.dropdownContent.offsetHeight;
980
- // dropdownFitsBelow = (dropdownBottom < windowBottom)
981
- var dropdownFitsBelow = inputTop + this.telInput.offsetHeight + dropdownHeight < windowTop + window.innerHeight;
982
- var dropdownFitsAbove = inputTop - dropdownHeight > windowTop;
983
- // dont allow positioning above when country search enabled as the search box jumps around as you filter countries
984
- var positionDropdownAboveInput = !this.options.countrySearch && !dropdownFitsBelow && dropdownFitsAbove;
985
- // by default, the dropdown will be below the input. If we want to position it above the
986
- // input, we add the dropup class.
987
- this._toggleClass(this.dropdownContent, "iti__dropdown-content--dropup", positionDropdownAboveInput);
988
- // if dropdownContainer is enabled, calculate postion
989
- if (this.options.dropdownContainer) {
990
- // if we want to position the dropdown below the input, we need to add the input height to the top value
991
- var extraTop = positionDropdownAboveInput ? 0 : this.telInput.offsetHeight;
992
- // calculate placement
993
- this.dropdown.style.top = "".concat(inputTop + extraTop, "px");
994
- this.dropdown.style.left = "".concat(pos.left + document.body.scrollLeft, "px");
995
- // close menu on window scroll
996
- this._handleWindowScroll = function() {
997
- return _this7._closeDropdown();
998
- };
999
- window.addEventListener("scroll", this._handleWindowScroll);
1000
- }
1001
- }
1002
- }
1003
- }, {
1004
- key: "_bindDropdownListeners",
1005
- value: function _bindDropdownListeners() {
1006
- var _this8 = this;
1007
- // when mouse over a list item, just highlight that one
1008
- // we add the class "highlight", so if they hit "enter" we know which one to select
1009
- this._handleMouseoverCountryList = function(e) {
1010
- // handle event delegation, as we're listening for this event on the countryList
1011
- var listItem = e.target.closest(".iti__country");
1012
- if (listItem) {
1013
- _this8._highlightListItem(listItem, false);
1014
- }
1015
- };
1016
- this.countryList.addEventListener("mouseover", this._handleMouseoverCountryList);
1017
- // listen for country selection
1018
- this._handleClickCountryList = function(e) {
1019
- var listItem = e.target.closest(".iti__country");
1020
- if (listItem) {
1021
- _this8._selectListItem(listItem);
1022
- }
1023
- };
1024
- this.countryList.addEventListener("click", this._handleClickCountryList);
1025
- // click off to close
1026
- // (except when this initial opening click is bubbling up)
1027
- // we cannot just stopPropagation as it may be needed to close another instance
1028
- var isOpening = true;
1029
- this._handleClickOffToClose = function() {
1030
- if (!isOpening) {
1031
- _this8._closeDropdown();
1032
- }
1033
- isOpening = false;
1034
- };
1035
- document.documentElement.addEventListener("click", this._handleClickOffToClose);
1036
- // listen for up/down scrolling, enter to select, or escape to close
1037
- // use keydown as keypress doesn't fire for non-char keys and we want to catch if they
1038
- // just hit down and hold it to scroll down (no keyup event).
1039
- // listen on the document because that's where key events are triggered if no input has focus
1040
- var query = "";
1041
- var queryTimer = null;
1042
- this._handleKeydownOnDropdown = function(e) {
1043
- // prevent down key from scrolling the whole page,
1044
- // and enter key from submitting a form etc
1045
- if ([ "ArrowUp", "ArrowDown", "Enter", "Escape" ].includes(e.key)) {
1046
- e.preventDefault();
1047
- e.stopPropagation();
1048
- // up and down to navigate
1049
- if (e.key === "ArrowUp" || e.key === "ArrowDown") {
1050
- _this8._handleUpDownKey(e.key);
1051
- } else if (e.key === "Enter") {
1052
- _this8._handleEnterKey();
1053
- } else if (e.key === "Escape") {
1054
- _this8._closeDropdown();
1055
- }
1056
- }
1057
- // alpha chars to perform search
1058
- // regex allows one latin alpha char or space, based on https://stackoverflow.com/a/26900132/217866)
1059
- if (!_this8.options.countrySearch && /^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(e.key)) {
1060
- e.stopPropagation();
1061
- // jump to countries that start with the query string
1062
- if (queryTimer) {
1063
- clearTimeout(queryTimer);
1064
- }
1065
- query += e.key.toLowerCase();
1066
- _this8._searchForCountry(query);
1067
- // if the timer hits 1 second, reset the query
1068
- queryTimer = setTimeout(function() {
1069
- query = "";
1070
- }, 1e3);
1071
- }
1072
- };
1073
- document.addEventListener("keydown", this._handleKeydownOnDropdown);
1074
- if (this.options.countrySearch) {
1075
- var doFilter = function doFilter() {
1076
- var inputQuery = _this8.searchInput.value.trim();
1077
- if (inputQuery) {
1078
- _this8._filterCountries(inputQuery);
1079
- } else {
1080
- _this8._filterCountries("", true);
1081
- }
1082
- };
1083
- var keyupTimer = null;
1084
- this._handleSearchChange = function() {
1085
- // filtering country nodes is expensive (lots of DOM manipulation), so rate limit it
1086
- if (keyupTimer) {
1087
- clearTimeout(keyupTimer);
1088
- }
1089
- keyupTimer = setTimeout(function() {
1090
- doFilter();
1091
- keyupTimer = null;
1092
- }, 100);
1093
- };
1094
- this.searchInput.addEventListener("input", this._handleSearchChange);
1095
- // stop propagation on search input click, so doesn't trigger click-off-to-close listener
1096
- this.searchInput.addEventListener("click", function(e) {
1097
- return e.stopPropagation();
1098
- });
1099
- }
1100
- }
1101
- }, {
1102
- key: "_normaliseString",
1103
- value: function _normaliseString() {
1104
- var s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
1105
- return s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
1106
- }
1107
- }, {
1108
- key: "_filterCountries",
1109
- value: function _filterCountries(query) {
1110
- var isReset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1111
- var isFirst = true;
1112
- this.countryList.innerHTML = "";
1113
- var normalisedQuery = this._normaliseString(query);
1114
- for (var i = 0; i < this.countries.length; i++) {
1115
- var c = this.countries[i];
1116
- var normalisedCountryName = this._normaliseString(c.name);
1117
- var fullDialCode = "+".concat(c.dialCode);
1118
- if (isReset || normalisedCountryName.includes(normalisedQuery) || fullDialCode.includes(normalisedQuery) || c.iso2.includes(normalisedQuery)) {
1119
- this.countryList.appendChild(c.nodeById[this.id]);
1120
- // highlight the first item
1121
- if (isFirst) {
1122
- this._highlightListItem(c.nodeById[this.id], false);
1123
- isFirst = false;
1124
- }
1125
- }
1126
- }
1127
- // scroll to top (useful if user had previously scrolled down)
1128
- this.countryList.scrollTop = 0;
1129
- this._updateSearchResultsText();
1130
- }
1131
- }, {
1132
- key: "_updateSearchResultsText",
1133
- value: function _updateSearchResultsText() {
1134
- var i18n = this.options.i18n;
1135
- var count = this.countryList.childElementCount;
1136
- var searchText;
1137
- if (count === 0) {
1138
- searchText = i18n.zeroSearchResults || "No results found";
1139
- } else if (count === 1) {
1140
- searchText = i18n.oneSearchResult || "1 result found";
1141
- } else {
1142
- // eslint-disable-next-line no-template-curly-in-string
1143
- searchText = i18n.multipleSearchResults ? i18n.multipleSearchResults.replace("${count}", count) : "".concat(count, " results found");
1144
- }
1145
- this.searchResultsA11yText.textContent = searchText;
1146
- }
1147
- }, {
1148
- key: "_handleUpDownKey",
1149
- value: function _handleUpDownKey(key) {
1150
- var next = key === "ArrowUp" ? this.highlightedItem.previousElementSibling : this.highlightedItem.nextElementSibling;
1151
- if (next) {
1152
- // skip the divider
1153
- if (next.classList.contains("iti__divider")) {
1154
- next = key === "ArrowUp" ? next.previousElementSibling : next.nextElementSibling;
1155
- }
1156
- } else if (this.countryList.childElementCount > 1) {
1157
- // otherwise, we must be at the end, so loop round again
1158
- next = key === "ArrowUp" ? this.countryList.lastElementChild : this.countryList.firstElementChild;
1159
- }
1160
- if (next) {
1161
- // make sure the next item is visible
1162
- // (before calling focus(), which can cause the next item to scroll to the middle of the dropdown, which is jarring)
1163
- this._scrollTo(next, false);
1164
- // if country search enabled, dont lose focus from the search input on up/down
1165
- var doFocus = !this.options.countrySearch;
1166
- this._highlightListItem(next, doFocus);
1167
- }
1168
- }
1169
- }, {
1170
- key: "_handleEnterKey",
1171
- value: function _handleEnterKey() {
1172
- if (this.highlightedItem) {
1173
- this._selectListItem(this.highlightedItem);
1174
- }
1175
- }
1176
- }, {
1177
- key: "_searchForCountry",
1178
- value: function _searchForCountry(query) {
1179
- for (var i = 0; i < this.countries.length; i++) {
1180
- if (this._startsWith(this.countries[i].name, query)) {
1181
- var listItem = this.countries[i].nodeById[this.id];
1182
- // update highlighting and scroll
1183
- this._highlightListItem(listItem, false);
1184
- this._scrollTo(listItem, true);
1185
- break;
1186
- }
1187
- }
1188
- }
1189
- }, {
1190
- key: "_startsWith",
1191
- value: function _startsWith(a, b) {
1192
- return a.substr(0, b.length).toLowerCase() === b;
1193
- }
1194
- }, {
1195
- key: "_updateValFromNumber",
1196
- value: function _updateValFromNumber(fullNumber) {
1197
- var number = fullNumber;
1198
- if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) {
1199
- var useNational = this.options.nationalMode || number.charAt(0) !== "+" && !this.options.showSelectedDialCode;
1200
- var _intlTelInputUtils$nu = intlTelInputUtils.numberFormat, NATIONAL = _intlTelInputUtils$nu.NATIONAL, INTERNATIONAL = _intlTelInputUtils$nu.INTERNATIONAL;
1201
- var format = useNational ? NATIONAL : INTERNATIONAL;
1202
- number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format);
1203
- }
1204
- number = this._beforeSetNumber(number);
1205
- this.telInput.value = number;
1206
- }
1207
- }, {
1208
- key: "_updateFlagFromNumber",
1209
- value: function _updateFlagFromNumber(fullNumber) {
1210
- var plusIndex = fullNumber.indexOf("+");
1211
- // if it contains a plus, discard any chars before it e.g. accidental space char.
1212
- // this keeps the selected country auto-updating correctly, which we want as
1213
- // libphonenumber's validation/getNumber methods will ignore these chars anyway
1214
- var number = plusIndex ? fullNumber.substring(plusIndex) : fullNumber;
1215
- // if we already have US/Canada selected, make sure the number starts
1216
- // with a +1 so _getDialCode will be able to extract the area code
1217
- // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag
1218
- // from the number), that means we're initialising the plugin with a number that already has a
1219
- // dial code, so fine to ignore this bit
1220
- var selectedDialCode = this.selectedCountryData.dialCode;
1221
- var isNanp = selectedDialCode === "1";
1222
- if (number && isNanp && number.charAt(0) !== "+") {
1223
- if (number.charAt(0) !== "1") {
1224
- number = "1".concat(number);
1225
- }
1226
- number = "+".concat(number);
1227
- }
1228
- // if showSelectedDialCode enabled, then consider the selected dial code to be part of the number
1229
- if (this.options.showSelectedDialCode && selectedDialCode && number.charAt(0) !== "+") {
1230
- number = "+".concat(selectedDialCode).concat(number);
1231
- }
1232
- // try and extract valid dial code from input
1233
- var dialCode = this._getDialCode(number, true);
1234
- var numeric = this._getNumeric(number);
1235
- var iso2 = null;
1236
- if (dialCode) {
1237
- var iso2Codes = this.dialCodeToIso2Map[this._getNumeric(dialCode)];
1238
- // check if the right country is already selected. this should be false if the number is
1239
- // longer than the matched dial code because in this case we need to make sure that if
1240
- // there are multiple country matches, that the first one is selected (note: we could
1241
- // just check that here, but it requires the same loop that we already have later)
1242
- var alreadySelected = iso2Codes.indexOf(this.selectedCountryData.iso2) !== -1 && numeric.length <= dialCode.length - 1;
1243
- var isRegionlessNanpNumber = selectedDialCode === "1" && this._isRegionlessNanp(numeric);
1244
- // only update the flag if:
1245
- // A) NOT (we currently have a NANP flag selected, and the number is a regionlessNanp)
1246
- // AND
1247
- // B) the right country is not already selected
1248
- if (!isRegionlessNanpNumber && !alreadySelected) {
1249
- // if using onlyCountries option, iso2Codes[0] may be empty, so we must find the first
1250
- // non-empty index
1251
- for (var j = 0; j < iso2Codes.length; j++) {
1252
- if (iso2Codes[j]) {
1253
- iso2 = iso2Codes[j];
1254
- break;
1255
- }
1256
- }
1257
- }
1258
- } else if (number.charAt(0) === "+" && numeric.length) {
1259
- // invalid dial code, so empty
1260
- // Note: use getNumeric here because the number has not been formatted yet, so could contain
1261
- // bad chars
1262
- iso2 = "";
1263
- } else if ((!number || number === "+") && !this.selectedCountryData.iso2) {
1264
- // if no selected flag, and user either clears the input, or just types a plus, then show default
1265
- iso2 = this.defaultCountry;
1266
- }
1267
- if (iso2 !== null) {
1268
- return this._setCountry(iso2);
1269
- }
1270
- return false;
1271
- }
1272
- }, {
1273
- key: "_isRegionlessNanp",
1274
- value: function _isRegionlessNanp(number) {
1275
- var numeric = this._getNumeric(number);
1276
- if (numeric.charAt(0) === "1") {
1277
- var areaCode = numeric.substr(1, 3);
1278
- return regionlessNanpNumbers.indexOf(areaCode) !== -1;
1279
- }
1280
- return false;
1281
- }
1282
- }, {
1283
- key: "_highlightListItem",
1284
- value: function _highlightListItem(listItem, shouldFocus) {
1285
- var prevItem = this.highlightedItem;
1286
- if (prevItem) {
1287
- prevItem.classList.remove("iti__highlight");
1288
- prevItem.setAttribute("aria-selected", "false");
1289
- }
1290
- this.highlightedItem = listItem;
1291
- this.highlightedItem.classList.add("iti__highlight");
1292
- this.highlightedItem.setAttribute("aria-selected", "true");
1293
- this.selectedFlag.setAttribute("aria-activedescendant", listItem.getAttribute("id"));
1294
- if (this.options.countrySearch) {
1295
- this.searchInput.setAttribute("aria-activedescendant", listItem.getAttribute("id"));
1296
- }
1297
- if (shouldFocus) {
1298
- this.highlightedItem.focus();
1299
- }
1300
- }
1301
- }, {
1302
- key: "_getCountryData",
1303
- value: function _getCountryData(iso2, allowFail) {
1304
- for (var i = 0; i < this.countries.length; i++) {
1305
- if (this.countries[i].iso2 === iso2) {
1306
- return this.countries[i];
1307
- }
1308
- }
1309
- if (allowFail) {
1310
- return null;
1311
- }
1312
- throw new Error("No country data for '".concat(iso2, "'"));
1313
- }
1314
- }, {
1315
- key: "_setCountry",
1316
- value: function _setCountry(iso2) {
1317
- var _this$options4 = this.options, allowDropdown = _this$options4.allowDropdown, showSelectedDialCode = _this$options4.showSelectedDialCode, showFlags = _this$options4.showFlags, countrySearch = _this$options4.countrySearch, i18n = _this$options4.i18n;
1318
- var prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {};
1319
- // do this first as it will throw an error and stop if iso2 is invalid
1320
- this.selectedCountryData = iso2 ? this._getCountryData(iso2, false) : {};
1321
- // update the defaultCountry - we only need the iso2 from now on, so just store that
1322
- if (this.selectedCountryData.iso2) {
1323
- this.defaultCountry = this.selectedCountryData.iso2;
1324
- }
1325
- // update the flag class and the a11y text
1326
- if (this.selectedFlagInner) {
1327
- var flagClass = "";
1328
- var a11yText = "";
1329
- if (iso2) {
1330
- if (showFlags) {
1331
- flagClass = "iti__flag iti__".concat(iso2);
1332
- a11yText = "".concat(this.selectedCountryData.name, " +").concat(this.selectedCountryData.dialCode);
1333
- }
1334
- } else {
1335
- flagClass = "iti__flag iti__globe";
1336
- a11yText = i18n.noCountrySelected || "No country selected";
1337
- }
1338
- this.selectedFlagInner.className = flagClass;
1339
- this.selectedFlagA11yText.textContent = a11yText;
1340
- }
1341
- this._setSelectedCountryFlagTitleAttribute(iso2, showSelectedDialCode);
1342
- // update the selected dial code
1343
- if (showSelectedDialCode) {
1344
- var dialCode = this.selectedCountryData.dialCode ? "+".concat(this.selectedCountryData.dialCode) : "";
1345
- this.selectedDialCode.innerHTML = dialCode;
1346
- // offsetWidth is zero if input is in a hidden container during initialisation
1347
- var selectedFlagWidth = this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth();
1348
- // add 6px of padding after the grey selected-dial-code box, as this is what we use in the css
1349
- if (this.isRTL) {
1350
- this.telInput.style.paddingRight = "".concat(selectedFlagWidth + 6, "px");
1351
- } else {
1352
- this.telInput.style.paddingLeft = "".concat(selectedFlagWidth + 6, "px");
1353
- }
1354
- }
1355
- // and the input's placeholder
1356
- this._updatePlaceholder();
1357
- // update the maximum valid number length
1358
- this._updateMaxLength();
1359
- // update the active list item (only if country search disabled, as country search doesn't store the active item)
1360
- if (allowDropdown && !countrySearch) {
1361
- var prevItem = this.activeItem;
1362
- if (prevItem) {
1363
- prevItem.classList.remove("iti__active");
1364
- prevItem.setAttribute("aria-selected", "false");
1365
- }
1366
- if (iso2) {
1367
- // check if there is a preferred item first, else fall back to standard
1368
- var nextItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(iso2, "-preferred")) || this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(iso2));
1369
- nextItem.setAttribute("aria-selected", "true");
1370
- nextItem.classList.add("iti__active");
1371
- this.activeItem = nextItem;
1372
- }
1373
- }
1374
- // return if the flag has changed or not
1375
- return prevCountry.iso2 !== iso2;
1376
- }
1377
- }, {
1378
- key: "_updateMaxLength",
1379
- value: function _updateMaxLength() {
1380
- if (this.options.strictMode && window.intlTelInputUtils) {
1381
- if (this.selectedCountryData.iso2) {
1382
- var numberType = intlTelInputUtils.numberType[this.options.placeholderNumberType];
1383
- var exampleNumber = intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, null, numberType, true);
1384
- // see if adding more digits is still valid to get the true maximum valid length
1385
- var validNumber = exampleNumber;
1386
- while (intlTelInputUtils.isPossibleNumber(exampleNumber, this.selectedCountryData.iso2)) {
1387
- validNumber = exampleNumber;
1388
- exampleNumber += "0";
1389
- }
1390
- var coreNumber = intlTelInputUtils.getCoreNumber(validNumber, this.selectedCountryData.iso2);
1391
- this.maxCoreNumberLength = coreNumber.length;
1392
- } else {
1393
- this.maxCoreNumberLength = null;
1394
- }
1395
- }
1396
- }
1397
- }, {
1398
- key: "_setSelectedCountryFlagTitleAttribute",
1399
- value: function _setSelectedCountryFlagTitleAttribute(iso2, showSelectedDialCode) {
1400
- if (!this.selectedFlag) {
1401
- return;
1402
- }
1403
- var title;
1404
- if (iso2 && !showSelectedDialCode) {
1405
- title = "".concat(this.selectedCountryData.name, ": +").concat(this.selectedCountryData.dialCode);
1406
- } else if (iso2) {
1407
- // For screen reader output, we don't want to include the dial code in the reader output twice
1408
- // so just use the selected country name here:
1409
- title = this.selectedCountryData.name;
1410
- } else {
1411
- title = "Unknown";
1412
- }
1413
- this.selectedFlag.setAttribute("title", title);
1414
- }
1415
- }, {
1416
- key: "_getHiddenSelectedFlagWidth",
1417
- value: function _getHiddenSelectedFlagWidth() {
1418
- // to get the right styling to apply, all we need is a shallow clone of the container,
1419
- // and then to inject a deep clone of the selectedFlag element
1420
- var containerClone = this.telInput.parentNode.cloneNode();
1421
- containerClone.style.visibility = "hidden";
1422
- document.body.appendChild(containerClone);
1423
- var flagsContainerClone = this.flagsContainer.cloneNode();
1424
- containerClone.appendChild(flagsContainerClone);
1425
- var selectedFlagClone = this.selectedFlag.cloneNode(true);
1426
- flagsContainerClone.appendChild(selectedFlagClone);
1427
- var width = selectedFlagClone.offsetWidth;
1428
- containerClone.parentNode.removeChild(containerClone);
1429
- return width;
1430
- }
1431
- }, {
1432
- key: "_updatePlaceholder",
1433
- value: function _updatePlaceholder() {
1434
- var _this$options5 = this.options, autoPlaceholder = _this$options5.autoPlaceholder, placeholderNumberType = _this$options5.placeholderNumberType, nationalMode = _this$options5.nationalMode, customPlaceholder = _this$options5.customPlaceholder;
1435
- var shouldSetPlaceholder = autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && autoPlaceholder === "polite";
1436
- if (window.intlTelInputUtils && shouldSetPlaceholder) {
1437
- var numberType = intlTelInputUtils.numberType[placeholderNumberType];
1438
- // note: must set placeholder to empty string if no country selected (globe icon showing)
1439
- var placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, nationalMode, numberType) : "";
1440
- placeholder = this._beforeSetNumber(placeholder);
1441
- if (typeof customPlaceholder === "function") {
1442
- placeholder = customPlaceholder(placeholder, this.selectedCountryData);
1443
- }
1444
- this.telInput.setAttribute("placeholder", placeholder);
1445
- }
1446
- }
1447
- }, {
1448
- key: "_selectListItem",
1449
- value: function _selectListItem(listItem) {
1450
- // update selected flag and active list item
1451
- var flagChanged = this._setCountry(listItem.getAttribute("data-country-code"));
1452
- this._closeDropdown();
1453
- this._updateDialCode(listItem.getAttribute("data-dial-code"));
1454
- // focus the input
1455
- this.telInput.focus();
1456
- if (flagChanged) {
1457
- this._triggerCountryChange();
1458
- }
1459
- }
1460
- }, {
1461
- key: "_closeDropdown",
1462
- value: function _closeDropdown() {
1463
- this.dropdownContent.classList.add("iti__hide");
1464
- this.selectedFlag.setAttribute("aria-expanded", "false");
1465
- this.selectedFlag.removeAttribute("aria-activedescendant");
1466
- if (this.highlightedItem) {
1467
- this.highlightedItem.setAttribute("aria-selected", "false");
1468
- }
1469
- if (this.options.countrySearch) {
1470
- this.searchInput.removeAttribute("aria-activedescendant");
1471
- }
1472
- // update the arrow
1473
- this.dropdownArrow.classList.remove("iti__arrow--up");
1474
- // unbind key events
1475
- document.removeEventListener("keydown", this._handleKeydownOnDropdown);
1476
- if (this.options.countrySearch) {
1477
- this.searchInput.removeEventListener("input", this._handleSearchChange);
1478
- }
1479
- document.documentElement.removeEventListener("click", this._handleClickOffToClose);
1480
- this.countryList.removeEventListener("mouseover", this._handleMouseoverCountryList);
1481
- this.countryList.removeEventListener("click", this._handleClickCountryList);
1482
- // remove menu from container
1483
- if (this.options.dropdownContainer) {
1484
- if (!this.options.useFullscreenPopup) {
1485
- window.removeEventListener("scroll", this._handleWindowScroll);
1486
- }
1487
- if (this.dropdown.parentNode) {
1488
- this.dropdown.parentNode.removeChild(this.dropdown);
1489
- }
1490
- }
1491
- this._trigger("close:countrydropdown");
1492
- }
1493
- }, {
1494
- key: "_scrollTo",
1495
- value: function _scrollTo(element, middle) {
1496
- var container = this.countryList;
1497
- // windowTop from https://stackoverflow.com/a/14384091/217866
1498
- var windowTop = document.documentElement.scrollTop;
1499
- var containerHeight = container.offsetHeight;
1500
- var containerTop = container.getBoundingClientRect().top + windowTop;
1501
- var containerBottom = containerTop + containerHeight;
1502
- var elementHeight = element.offsetHeight;
1503
- var elementTop = element.getBoundingClientRect().top + windowTop;
1504
- var elementBottom = elementTop + elementHeight;
1505
- var newScrollTop = elementTop - containerTop + container.scrollTop;
1506
- var middleOffset = containerHeight / 2 - elementHeight / 2;
1507
- if (elementTop < containerTop) {
1508
- // scroll up
1509
- if (middle) {
1510
- newScrollTop -= middleOffset;
1511
- }
1512
- container.scrollTop = newScrollTop;
1513
- } else if (elementBottom > containerBottom) {
1514
- // scroll down
1515
- if (middle) {
1516
- newScrollTop += middleOffset;
1517
- }
1518
- var heightDifference = containerHeight - elementHeight;
1519
- container.scrollTop = newScrollTop - heightDifference;
1520
- }
1521
- }
1522
- }, {
1523
- key: "_updateDialCode",
1524
- value: function _updateDialCode(newDialCodeBare) {
1525
- var inputVal = this.telInput.value;
1526
- // save having to pass this every time
1527
- var newDialCode = "+".concat(newDialCodeBare);
1528
- var newNumber;
1529
- if (inputVal.charAt(0) === "+") {
1530
- // there's a plus so we're dealing with a replacement
1531
- var prevDialCode = this._getDialCode(inputVal);
1532
- if (prevDialCode) {
1533
- // current number contains a valid dial code, so replace it
1534
- newNumber = inputVal.replace(prevDialCode, newDialCode);
1535
- } else {
1536
- // current number contains an invalid dial code, so ditch it
1537
- // (no way to determine where the invalid dial code ends and the rest of the number begins)
1538
- newNumber = newDialCode;
1539
- }
1540
- this.telInput.value = newNumber;
1541
- }
1542
- }
1543
- }, {
1544
- key: "_getDialCode",
1545
- value: function _getDialCode(number, includeAreaCode) {
1546
- var dialCode = "";
1547
- // only interested in international numbers (starting with a plus)
1548
- if (number.charAt(0) === "+") {
1549
- var numericChars = "";
1550
- // iterate over chars
1551
- for (var i = 0; i < number.length; i++) {
1552
- var c = number.charAt(i);
1553
- // if char is number (https://stackoverflow.com/a/8935649/217866)
1554
- if (!isNaN(parseInt(c, 10))) {
1555
- numericChars += c;
1556
- // if current numericChars make a valid dial code
1557
- if (includeAreaCode) {
1558
- if (this.dialCodeToIso2Map[numericChars]) {
1559
- // store the actual raw string (useful for matching later)
1560
- dialCode = number.substr(0, i + 1);
1561
- }
1562
- } else {
1563
- if (this.dialCodes[numericChars]) {
1564
- dialCode = number.substr(0, i + 1);
1565
- // if we're just looking for a dial code, we can break as soon as we find one
1566
- break;
1567
- }
1568
- }
1569
- // stop searching as soon as we can - in this case when we hit max len
1570
- if (numericChars.length === this.dialCodeMaxLen) {
1571
- break;
1572
- }
1573
- }
1574
- }
1575
- }
1576
- return dialCode;
1577
- }
1578
- }, {
1579
- key: "_getFullNumber",
1580
- value: function _getFullNumber() {
1581
- var val = this.telInput.value.trim();
1582
- var dialCode = this.selectedCountryData.dialCode;
1583
- var prefix;
1584
- var numericVal = this._getNumeric(val);
1585
- if (this.options.showSelectedDialCode && !this.options.nationalMode && val.charAt(0) !== "+" && dialCode && numericVal) {
1586
- // when using showSelectedDialCode, it is visible so is effectively part of the typed number
1587
- prefix = "+".concat(dialCode);
1588
- } else {
1589
- prefix = "";
1590
- }
1591
- return prefix + val;
1592
- }
1593
- }, {
1594
- key: "_beforeSetNumber",
1595
- value: function _beforeSetNumber(fullNumber) {
1596
- var number = fullNumber;
1597
- if (this.options.showSelectedDialCode) {
1598
- var dialCode = this._getDialCode(number);
1599
- // if there is a valid dial code
1600
- if (dialCode) {
1601
- // in case _getDialCode returned an area code as well
1602
- dialCode = "+".concat(this.selectedCountryData.dialCode);
1603
- // a lot of numbers will have a space separating the dial code and the main number, and
1604
- // some NANP numbers will have a hyphen e.g. +1 684-733-1234 - in both cases we want to get
1605
- // rid of it
1606
- // NOTE: don't just trim all non-numerics as may want to preserve an open parenthesis etc
1607
- var start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
1608
- number = number.substr(start);
1609
- }
1610
- }
1611
- return this._cap(number);
1612
- }
1613
- }, {
1614
- key: "_triggerCountryChange",
1615
- value: function _triggerCountryChange() {
1616
- this._trigger("countrychange");
1617
- }
1618
- }, {
1619
- key: "_formatNumberAsYouType",
1620
- value: function _formatNumberAsYouType() {
1621
- var val = this._getFullNumber();
1622
- var result = window.intlTelInputUtils ? intlTelInputUtils.formatNumberAsYouType(val, this.selectedCountryData.iso2) : val;
1623
- // if showSelectedDialCode and they haven't (re)typed the dial code in the input as well, then remove the dial code
1624
- var dialCode = this.selectedCountryData.dialCode;
1625
- if (this.options.showSelectedDialCode && !this.options.nationalMode && this.telInput.value.charAt(0) !== "+" && result.includes("+".concat(dialCode))) {
1626
- var afterDialCode = result.split("+".concat(dialCode))[1] || "";
1627
- return afterDialCode.trim();
1628
- }
1629
- return result;
1630
- }
1631
- }, {
1632
- key: "handleAutoCountry",
1633
- value: function handleAutoCountry() {
1634
- if (this.options.initialCountry === "auto") {
1635
- // we must set this even if there is an initial val in the input: in case the initial val is
1636
- // invalid and they delete it - they should see their auto country
1637
- this.defaultCountry = window.intlTelInputGlobals.autoCountry;
1638
- // if there's no initial value in the input, then update the flag
1639
- if (!this.telInput.value) {
1640
- this.setCountry(this.defaultCountry);
1641
- }
1642
- this.resolveAutoCountryPromise();
1643
- }
1644
- }
1645
- }, {
1646
- key: "handleUtils",
1647
- value: function handleUtils() {
1648
- // if the request was successful
1649
- if (window.intlTelInputUtils) {
1650
- // if there's an initial value in the input, then format it
1651
- if (this.telInput.value) {
1652
- this._updateValFromNumber(this.telInput.value);
1653
- }
1654
- if (this.selectedCountryData.iso2) {
1655
- this._updatePlaceholder();
1656
- this._updateMaxLength();
1657
- }
1658
- }
1659
- this.resolveUtilsScriptPromise();
1660
- }
1661
- }, {
1662
- key: "destroy",
1663
- value: function destroy() {
1664
- if (this.options.allowDropdown) {
1665
- // make sure the dropdown is closed (and unbind listeners)
1666
- this._closeDropdown();
1667
- this.selectedFlag.removeEventListener("click", this._handleClickSelectedFlag);
1668
- this.flagsContainer.removeEventListener("keydown", this._handleFlagsContainerKeydown);
1669
- // label click hack
1670
- var label = this.telInput.closest("label");
1671
- if (label) {
1672
- label.removeEventListener("click", this._handleLabelClick);
1673
- }
1674
- }
1675
- // unbind hiddenInput listeners
1676
- var form = this.telInput.form;
1677
- if (this._handleHiddenInputSubmit && form) {
1678
- form.removeEventListener("submit", this._handleHiddenInputSubmit);
1679
- }
1680
- // unbind key events, and cut/paste events
1681
- this.telInput.removeEventListener("input", this._handleInputEvent);
1682
- if (this._handleKeydownEvent) {
1683
- this.telInput.removeEventListener("keydown", this._handleKeydownEvent);
1684
- }
1685
- // remove attribute of id instance: data-intl-tel-input-id
1686
- this.telInput.removeAttribute("data-intl-tel-input-id");
1687
- // remove markup (but leave the original input)
1688
- var wrapper = this.telInput.parentNode;
1689
- wrapper.parentNode.insertBefore(this.telInput, wrapper);
1690
- wrapper.parentNode.removeChild(wrapper);
1691
- delete window.intlTelInputGlobals.instances[this.id];
1692
- }
1693
- }, {
1694
- key: "getExtension",
1695
- value: function getExtension() {
1696
- if (window.intlTelInputUtils) {
1697
- return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2);
1698
- }
1699
- return "";
1700
- }
1701
- }, {
1702
- key: "getNumber",
1703
- value: function getNumber(format) {
1704
- if (window.intlTelInputUtils) {
1705
- var iso2 = this.selectedCountryData.iso2;
1706
- return intlTelInputUtils.formatNumber(this._getFullNumber(), iso2, format);
1707
- }
1708
- return "";
1709
- }
1710
- }, {
1711
- key: "getNumberType",
1712
- value: function getNumberType() {
1713
- if (window.intlTelInputUtils) {
1714
- return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2);
1715
- }
1716
- return -99;
1717
- }
1718
- }, {
1719
- key: "getSelectedCountryData",
1720
- value: function getSelectedCountryData() {
1721
- return this.selectedCountryData;
1722
- }
1723
- }, {
1724
- key: "getValidationError",
1725
- value: function getValidationError() {
1726
- if (window.intlTelInputUtils) {
1727
- var iso2 = this.selectedCountryData.iso2;
1728
- return intlTelInputUtils.getValidationError(this._getFullNumber(), iso2);
1729
- }
1730
- return -99;
1731
- }
1732
- }, {
1733
- key: "isValidNumber",
1734
- value: function isValidNumber() {
1735
- var mobileOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1736
- var val = this._getFullNumber();
1737
- // return false for any alpha chars
1738
- if (/(?:[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDF70-\uDF81\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE3F\uDE40\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2\uDF02\uDF04-\uDF10\uDF12-\uDF33\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC41-\uDC46]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE70-\uDEBE\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC30-\uDC6D\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB]|\uD839[\uDCD0-\uDCEB\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0\uDFF0-\uDFFF]|\uD87B[\uDC00-\uDE5D]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF])/.test(val)) {
1739
- return false;
1740
- }
1741
- return window.intlTelInputUtils ? intlTelInputUtils.isPossibleNumber(val, this.selectedCountryData.iso2, mobileOnly) : null;
1742
- }
1743
- }, {
1744
- key: "isValidNumberPrecise",
1745
- value: function isValidNumberPrecise() {
1746
- var val = this._getFullNumber();
1747
- // return false for any alpha chars
1748
- if (/(?:[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDD00-\uDD23\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF1C\uDF27\uDF30-\uDF45\uDF70-\uDF81\uDFB0-\uDFC4\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE3F\uDE40\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDEB8\uDF00-\uDF1A\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCDF\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDEE0-\uDEF2\uDF02\uDF04-\uDF10\uDF12-\uDF33\uDFB0]|\uD808[\uDC00-\uDF99]|\uD809[\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2F\uDC41-\uDC46]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE70-\uDEBE\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE7F\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD837[\uDF00-\uDF1E\uDF25-\uDF2A]|\uD838[\uDC30-\uDC6D\uDD00-\uDD2C\uDD37-\uDD3D\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB]|\uD839[\uDCD0-\uDCEB\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43\uDD4B]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0\uDFF0-\uDFFF]|\uD87B[\uDC00-\uDE5D]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF])/.test(val)) {
1749
- return false;
1750
- }
1751
- return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, this.selectedCountryData.iso2) : null;
1752
- }
1753
- }, {
1754
- key: "setCountry",
1755
- value: function setCountry(iso2) {
1756
- var iso2Lower = iso2.toLowerCase();
1757
- // check if already selected
1758
- if (this.selectedCountryData.iso2 !== iso2Lower) {
1759
- this._setCountry(iso2Lower);
1760
- this._updateDialCode(this.selectedCountryData.dialCode);
1761
- this._triggerCountryChange();
1762
- }
1763
- }
1764
- }, {
1765
- key: "setNumber",
1766
- value: function setNumber(number) {
1767
- // we must update the flag first, which updates this.selectedCountryData, which is used for
1768
- // formatting the number before displaying it
1769
- var flagChanged = this._updateFlagFromNumber(number);
1770
- this._updateValFromNumber(number);
1771
- if (flagChanged) {
1772
- this._triggerCountryChange();
1773
- }
1774
- }
1775
- }, {
1776
- key: "setPlaceholderNumberType",
1777
- value: function setPlaceholderNumberType(type) {
1778
- this.options.placeholderNumberType = type;
1779
- this._updatePlaceholder();
1780
- }
1781
- } ]);
1782
- return Iti;
1783
- }();
1784
- /********************
1785
- * STATIC METHODS
1786
- ********************/
1787
- // get the country data object
1788
- intlTelInputGlobals.getCountryData = function() {
1789
- return allCountries;
1790
- };
1791
- // inject a <script> element to load utils.js
1792
- var injectScript = function injectScript(path, handleSuccess, handleFailure) {
1793
- // inject a new script element into the page
1794
- var script = document.createElement("script");
1795
- script.onload = function() {
1796
- forEachInstance("handleUtils");
1797
- if (handleSuccess) {
1798
- handleSuccess();
1799
- }
1800
- };
1801
- script.onerror = function() {
1802
- forEachInstance("rejectUtilsScriptPromise");
1803
- if (handleFailure) {
1804
- handleFailure();
1805
- }
1806
- };
1807
- script.className = "iti-load-utils";
1808
- script.async = true;
1809
- script.src = path;
1810
- document.body.appendChild(script);
1811
- };
1812
- // load the utils script
1813
- intlTelInputGlobals.loadUtils = function(path) {
1814
- // 2 options:
1815
- // 1) not already started loading (start)
1816
- // 2) already started loading (do nothing - just wait for the onload callback to fire, which will
1817
- // trigger handleUtils on all instances, invoking their resolveUtilsScriptPromise functions)
1818
- if (!window.intlTelInputUtils && !window.intlTelInputGlobals.startedLoadingUtilsScript) {
1819
- // only do this once
1820
- window.intlTelInputGlobals.startedLoadingUtilsScript = true;
1821
- return new Promise(function(resolve, reject) {
1822
- return injectScript(path, resolve, reject);
1823
- });
1824
- }
1825
- return null;
1826
- };
1827
- // default options
1828
- intlTelInputGlobals.defaults = defaults;
1829
- // version
1830
- intlTelInputGlobals.version = "20.2.0";
1831
- var pluginName = "intlTelInput";
1832
- // A really lightweight plugin wrapper around the constructor,
1833
- // preventing against multiple instantiations
1834
- $.fn[pluginName] = function(options) {
1835
- var args = arguments;
1836
- // Is the first parameter an object (options), or was omitted, instantiate a new instance of the plugin.
1837
- if (options === undefined || typeof options === "object") {
1838
- return this.each(function() {
1839
- if (!$.data(this, "plugin_" + pluginName)) {
1840
- var iti = new Iti(this, options);
1841
- iti._init();
1842
- window.intlTelInputGlobals.instances[iti.id] = iti;
1843
- $.data(this, "plugin_" + pluginName, iti);
1844
- }
1845
- });
1846
- } else if (typeof options === "string" && options[0] !== "_") {
1847
- // If the first parameter is a string and it doesn't start with an underscore treat this as a call to a public method.
1848
- // Cache the method call to make it possible to return a value
1849
- var returns;
1850
- this.each(function() {
1851
- var instance = $.data(this, "plugin_" + pluginName);
1852
- // Tests that there's already a plugin-instance and checks that the requested public method exists
1853
- if (instance instanceof Iti && typeof instance[options] === "function") {
1854
- // Call the method of our plugin instance, and pass it the supplied arguments.
1855
- returns = instance[options].apply(instance, Array.prototype.slice.call(args, 1));
1856
- }
1857
- // Allow instances to be destroyed via the 'destroy' method
1858
- if (options === "destroy") $.data(this, "plugin_" + pluginName, null);
1859
- });
1860
- // If the earlier cached method gives a value back return the value, otherwise return this to preserve chainability.
1861
- return returns !== undefined ? returns : this;
1862
- }
1863
- };
1864
- });