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,1835 +1,2878 @@
1
1
  /*
2
- * International Telephone Input v20.2.0
2
+ * International Telephone Input v21.0.0
3
3
  * https://github.com/jackocnr/intl-tel-input.git
4
4
  * Licensed under the MIT license
5
5
  */
6
6
 
7
- // wrap in UMD
7
+ // UMD
8
8
  (function(factory) {
9
- if (typeof module === "object" && module.exports) module.exports = factory(); else window.intlTelInput = factory();
10
- })(function(undefined) {
11
- "use strict";
12
- return function() {
13
- // Array of country objects for the flag dropdown.
14
- // Here is the criteria for the plugin to support a given country/territory
15
- // - It has an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
16
- // - 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
17
- // - It has a flag in the region-flags project: https://github.com/behdad/region-flags/tree/gh-pages/png
18
- // - It is supported by libphonenumber (it must be listed on this page): https://github.com/googlei18n/libphonenumber/blob/master/resources/ShortNumberMetadata.xml
19
- // Each country array has the following information:
20
- // [
21
- // Country name,
22
- // iso2 code,
23
- // International dial code,
24
- // Order (if >1 country with same dial code),
25
- // Area codes
26
- // ]
27
- 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" ] ] ];
28
- // loop over all of the countries above, restructuring the data to be objects with named keys
29
- for (var i = 0; i < allCountries.length; i++) {
30
- var c = allCountries[i];
31
- allCountries[i] = {
32
- name: c[0],
33
- iso2: c[1],
34
- dialCode: c[2],
35
- priority: c[3] || 0,
36
- areaCodes: c[4] || null,
37
- nodeById: {}
38
- };
9
+ if (typeof module === 'object' && module.exports) {
10
+ module.exports = factory();
11
+ } else {
12
+ window.intlTelInput = factory();
13
+ }
14
+ }(() => {
15
+
16
+ var factoryOutput = (() => {
17
+ var __defProp = Object.defineProperty;
18
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
19
+ var __getOwnPropNames = Object.getOwnPropertyNames;
20
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
21
+ var __export = (target, all) => {
22
+ for (var name in all)
23
+ __defProp(target, name, { get: all[name], enumerable: true });
24
+ };
25
+ var __copyProps = (to, from, except, desc) => {
26
+ if (from && typeof from === "object" || typeof from === "function") {
27
+ for (let key of __getOwnPropNames(from))
28
+ if (!__hasOwnProp.call(to, key) && key !== except)
29
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
+ }
31
+ return to;
32
+ };
33
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
+
35
+ // src/js/intlTelInput.ts
36
+ var intlTelInput_exports = {};
37
+ __export(intlTelInput_exports, {
38
+ Iti: () => Iti,
39
+ default: () => intlTelInput_default
40
+ });
41
+
42
+ // src/js/data.ts
43
+ var rawCountryData = [
44
+ [
45
+ "Afghanistan",
46
+ "af",
47
+ "93"
48
+ ],
49
+ [
50
+ "Albania",
51
+ "al",
52
+ "355"
53
+ ],
54
+ [
55
+ "Algeria",
56
+ "dz",
57
+ "213"
58
+ ],
59
+ [
60
+ "American Samoa",
61
+ "as",
62
+ "1",
63
+ 5,
64
+ ["684"]
65
+ ],
66
+ [
67
+ "Andorra",
68
+ "ad",
69
+ "376"
70
+ ],
71
+ [
72
+ "Angola",
73
+ "ao",
74
+ "244"
75
+ ],
76
+ [
77
+ "Anguilla",
78
+ "ai",
79
+ "1",
80
+ 6,
81
+ ["264"]
82
+ ],
83
+ [
84
+ "Antigua & Barbuda",
85
+ "ag",
86
+ "1",
87
+ 7,
88
+ ["268"]
89
+ ],
90
+ [
91
+ "Argentina",
92
+ "ar",
93
+ "54"
94
+ ],
95
+ [
96
+ "Armenia",
97
+ "am",
98
+ "374"
99
+ ],
100
+ [
101
+ "Aruba",
102
+ "aw",
103
+ "297"
104
+ ],
105
+ [
106
+ "Ascension Island",
107
+ "ac",
108
+ "247"
109
+ ],
110
+ [
111
+ "Australia",
112
+ "au",
113
+ "61",
114
+ 0
115
+ ],
116
+ [
117
+ "Austria",
118
+ "at",
119
+ "43"
120
+ ],
121
+ [
122
+ "Azerbaijan",
123
+ "az",
124
+ "994"
125
+ ],
126
+ [
127
+ "Bahamas",
128
+ "bs",
129
+ "1",
130
+ 8,
131
+ ["242"]
132
+ ],
133
+ [
134
+ "Bahrain",
135
+ "bh",
136
+ "973"
137
+ ],
138
+ [
139
+ "Bangladesh",
140
+ "bd",
141
+ "880"
142
+ ],
143
+ [
144
+ "Barbados",
145
+ "bb",
146
+ "1",
147
+ 9,
148
+ ["246"]
149
+ ],
150
+ [
151
+ "Belarus",
152
+ "by",
153
+ "375"
154
+ ],
155
+ [
156
+ "Belgium",
157
+ "be",
158
+ "32"
159
+ ],
160
+ [
161
+ "Belize",
162
+ "bz",
163
+ "501"
164
+ ],
165
+ [
166
+ "Benin",
167
+ "bj",
168
+ "229"
169
+ ],
170
+ [
171
+ "Bermuda",
172
+ "bm",
173
+ "1",
174
+ 10,
175
+ ["441"]
176
+ ],
177
+ [
178
+ "Bhutan",
179
+ "bt",
180
+ "975"
181
+ ],
182
+ [
183
+ "Bolivia",
184
+ "bo",
185
+ "591"
186
+ ],
187
+ [
188
+ "Bosnia & Herzegovina",
189
+ "ba",
190
+ "387"
191
+ ],
192
+ [
193
+ "Botswana",
194
+ "bw",
195
+ "267"
196
+ ],
197
+ [
198
+ "Brazil",
199
+ "br",
200
+ "55"
201
+ ],
202
+ [
203
+ "British Indian Ocean Territory",
204
+ "io",
205
+ "246"
206
+ ],
207
+ [
208
+ "British Virgin Islands",
209
+ "vg",
210
+ "1",
211
+ 11,
212
+ ["284"]
213
+ ],
214
+ [
215
+ "Brunei",
216
+ "bn",
217
+ "673"
218
+ ],
219
+ [
220
+ "Bulgaria",
221
+ "bg",
222
+ "359"
223
+ ],
224
+ [
225
+ "Burkina Faso",
226
+ "bf",
227
+ "226"
228
+ ],
229
+ [
230
+ "Burundi",
231
+ "bi",
232
+ "257"
233
+ ],
234
+ [
235
+ "Cambodia",
236
+ "kh",
237
+ "855"
238
+ ],
239
+ [
240
+ "Cameroon",
241
+ "cm",
242
+ "237"
243
+ ],
244
+ [
245
+ "Canada",
246
+ "ca",
247
+ "1",
248
+ 1,
249
+ ["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"]
250
+ ],
251
+ [
252
+ "Cape Verde",
253
+ "cv",
254
+ "238"
255
+ ],
256
+ [
257
+ "Caribbean Netherlands",
258
+ "bq",
259
+ "599",
260
+ 1,
261
+ ["3", "4", "7"]
262
+ ],
263
+ [
264
+ "Cayman Islands",
265
+ "ky",
266
+ "1",
267
+ 12,
268
+ ["345"]
269
+ ],
270
+ [
271
+ "Central African Republic",
272
+ "cf",
273
+ "236"
274
+ ],
275
+ [
276
+ "Chad",
277
+ "td",
278
+ "235"
279
+ ],
280
+ [
281
+ "Chile",
282
+ "cl",
283
+ "56"
284
+ ],
285
+ [
286
+ "China",
287
+ "cn",
288
+ "86"
289
+ ],
290
+ [
291
+ "Christmas Island",
292
+ "cx",
293
+ "61",
294
+ 2,
295
+ ["89164"]
296
+ ],
297
+ [
298
+ "Cocos (Keeling) Islands",
299
+ "cc",
300
+ "61",
301
+ 1,
302
+ ["89162"]
303
+ ],
304
+ [
305
+ "Colombia",
306
+ "co",
307
+ "57"
308
+ ],
309
+ [
310
+ "Comoros",
311
+ "km",
312
+ "269"
313
+ ],
314
+ [
315
+ "Congo - Brazzaville",
316
+ "cg",
317
+ "242"
318
+ ],
319
+ [
320
+ "Congo - Kinshasa",
321
+ "cd",
322
+ "243"
323
+ ],
324
+ [
325
+ "Cook Islands",
326
+ "ck",
327
+ "682"
328
+ ],
329
+ [
330
+ "Costa Rica",
331
+ "cr",
332
+ "506"
333
+ ],
334
+ [
335
+ "C\xF4te d\u2019Ivoire",
336
+ "ci",
337
+ "225"
338
+ ],
339
+ [
340
+ "Croatia",
341
+ "hr",
342
+ "385"
343
+ ],
344
+ [
345
+ "Cuba",
346
+ "cu",
347
+ "53"
348
+ ],
349
+ [
350
+ "Cura\xE7ao",
351
+ "cw",
352
+ "599",
353
+ 0
354
+ ],
355
+ [
356
+ "Cyprus",
357
+ "cy",
358
+ "357"
359
+ ],
360
+ [
361
+ "Czech Republic",
362
+ "cz",
363
+ "420"
364
+ ],
365
+ [
366
+ "Denmark",
367
+ "dk",
368
+ "45"
369
+ ],
370
+ [
371
+ "Djibouti",
372
+ "dj",
373
+ "253"
374
+ ],
375
+ [
376
+ "Dominica",
377
+ "dm",
378
+ "1",
379
+ 13,
380
+ ["767"]
381
+ ],
382
+ [
383
+ "Dominican Republic",
384
+ "do",
385
+ "1",
386
+ 2,
387
+ ["809", "829", "849"]
388
+ ],
389
+ [
390
+ "Ecuador",
391
+ "ec",
392
+ "593"
393
+ ],
394
+ [
395
+ "Egypt",
396
+ "eg",
397
+ "20"
398
+ ],
399
+ [
400
+ "El Salvador",
401
+ "sv",
402
+ "503"
403
+ ],
404
+ [
405
+ "Equatorial Guinea",
406
+ "gq",
407
+ "240"
408
+ ],
409
+ [
410
+ "Eritrea",
411
+ "er",
412
+ "291"
413
+ ],
414
+ [
415
+ "Estonia",
416
+ "ee",
417
+ "372"
418
+ ],
419
+ [
420
+ "Eswatini",
421
+ "sz",
422
+ "268"
423
+ ],
424
+ [
425
+ "Ethiopia",
426
+ "et",
427
+ "251"
428
+ ],
429
+ [
430
+ "Falkland Islands",
431
+ "fk",
432
+ "500"
433
+ ],
434
+ [
435
+ "Faroe Islands",
436
+ "fo",
437
+ "298"
438
+ ],
439
+ [
440
+ "Fiji",
441
+ "fj",
442
+ "679"
443
+ ],
444
+ [
445
+ "Finland",
446
+ "fi",
447
+ "358",
448
+ 0
449
+ ],
450
+ [
451
+ "France",
452
+ "fr",
453
+ "33"
454
+ ],
455
+ [
456
+ "French Guiana",
457
+ "gf",
458
+ "594"
459
+ ],
460
+ [
461
+ "French Polynesia",
462
+ "pf",
463
+ "689"
464
+ ],
465
+ [
466
+ "Gabon",
467
+ "ga",
468
+ "241"
469
+ ],
470
+ [
471
+ "Gambia",
472
+ "gm",
473
+ "220"
474
+ ],
475
+ [
476
+ "Georgia",
477
+ "ge",
478
+ "995"
479
+ ],
480
+ [
481
+ "Germany",
482
+ "de",
483
+ "49"
484
+ ],
485
+ [
486
+ "Ghana",
487
+ "gh",
488
+ "233"
489
+ ],
490
+ [
491
+ "Gibraltar",
492
+ "gi",
493
+ "350"
494
+ ],
495
+ [
496
+ "Greece",
497
+ "gr",
498
+ "30"
499
+ ],
500
+ [
501
+ "Greenland",
502
+ "gl",
503
+ "299"
504
+ ],
505
+ [
506
+ "Grenada",
507
+ "gd",
508
+ "1",
509
+ 14,
510
+ ["473"]
511
+ ],
512
+ [
513
+ "Guadeloupe",
514
+ "gp",
515
+ "590",
516
+ 0
517
+ ],
518
+ [
519
+ "Guam",
520
+ "gu",
521
+ "1",
522
+ 15,
523
+ ["671"]
524
+ ],
525
+ [
526
+ "Guatemala",
527
+ "gt",
528
+ "502"
529
+ ],
530
+ [
531
+ "Guernsey",
532
+ "gg",
533
+ "44",
534
+ 1,
535
+ ["1481", "7781", "7839", "7911"]
536
+ ],
537
+ [
538
+ "Guinea",
539
+ "gn",
540
+ "224"
541
+ ],
542
+ [
543
+ "Guinea-Bissau",
544
+ "gw",
545
+ "245"
546
+ ],
547
+ [
548
+ "Guyana",
549
+ "gy",
550
+ "592"
551
+ ],
552
+ [
553
+ "Haiti",
554
+ "ht",
555
+ "509"
556
+ ],
557
+ [
558
+ "Honduras",
559
+ "hn",
560
+ "504"
561
+ ],
562
+ [
563
+ "Hong Kong",
564
+ "hk",
565
+ "852"
566
+ ],
567
+ [
568
+ "Hungary",
569
+ "hu",
570
+ "36"
571
+ ],
572
+ [
573
+ "Iceland",
574
+ "is",
575
+ "354"
576
+ ],
577
+ [
578
+ "India",
579
+ "in",
580
+ "91"
581
+ ],
582
+ [
583
+ "Indonesia",
584
+ "id",
585
+ "62"
586
+ ],
587
+ [
588
+ "Iran",
589
+ "ir",
590
+ "98"
591
+ ],
592
+ [
593
+ "Iraq",
594
+ "iq",
595
+ "964"
596
+ ],
597
+ [
598
+ "Ireland",
599
+ "ie",
600
+ "353"
601
+ ],
602
+ [
603
+ "Isle of Man",
604
+ "im",
605
+ "44",
606
+ 2,
607
+ ["1624", "74576", "7524", "7924", "7624"]
608
+ ],
609
+ [
610
+ "Israel",
611
+ "il",
612
+ "972"
613
+ ],
614
+ [
615
+ "Italy",
616
+ "it",
617
+ "39",
618
+ 0
619
+ ],
620
+ [
621
+ "Jamaica",
622
+ "jm",
623
+ "1",
624
+ 4,
625
+ ["876", "658"]
626
+ ],
627
+ [
628
+ "Japan",
629
+ "jp",
630
+ "81"
631
+ ],
632
+ [
633
+ "Jersey",
634
+ "je",
635
+ "44",
636
+ 3,
637
+ ["1534", "7509", "7700", "7797", "7829", "7937"]
638
+ ],
639
+ [
640
+ "Jordan",
641
+ "jo",
642
+ "962"
643
+ ],
644
+ [
645
+ "Kazakhstan",
646
+ "kz",
647
+ "7",
648
+ 1,
649
+ ["33", "7"]
650
+ ],
651
+ [
652
+ "Kenya",
653
+ "ke",
654
+ "254"
655
+ ],
656
+ [
657
+ "Kiribati",
658
+ "ki",
659
+ "686"
660
+ ],
661
+ [
662
+ "Kosovo",
663
+ "xk",
664
+ "383"
665
+ ],
666
+ [
667
+ "Kuwait",
668
+ "kw",
669
+ "965"
670
+ ],
671
+ [
672
+ "Kyrgyzstan",
673
+ "kg",
674
+ "996"
675
+ ],
676
+ [
677
+ "Laos",
678
+ "la",
679
+ "856"
680
+ ],
681
+ [
682
+ "Latvia",
683
+ "lv",
684
+ "371"
685
+ ],
686
+ [
687
+ "Lebanon",
688
+ "lb",
689
+ "961"
690
+ ],
691
+ [
692
+ "Lesotho",
693
+ "ls",
694
+ "266"
695
+ ],
696
+ [
697
+ "Liberia",
698
+ "lr",
699
+ "231"
700
+ ],
701
+ [
702
+ "Libya",
703
+ "ly",
704
+ "218"
705
+ ],
706
+ [
707
+ "Liechtenstein",
708
+ "li",
709
+ "423"
710
+ ],
711
+ [
712
+ "Lithuania",
713
+ "lt",
714
+ "370"
715
+ ],
716
+ [
717
+ "Luxembourg",
718
+ "lu",
719
+ "352"
720
+ ],
721
+ [
722
+ "Macau",
723
+ "mo",
724
+ "853"
725
+ ],
726
+ [
727
+ "Madagascar",
728
+ "mg",
729
+ "261"
730
+ ],
731
+ [
732
+ "Malawi",
733
+ "mw",
734
+ "265"
735
+ ],
736
+ [
737
+ "Malaysia",
738
+ "my",
739
+ "60"
740
+ ],
741
+ [
742
+ "Maldives",
743
+ "mv",
744
+ "960"
745
+ ],
746
+ [
747
+ "Mali",
748
+ "ml",
749
+ "223"
750
+ ],
751
+ [
752
+ "Malta",
753
+ "mt",
754
+ "356"
755
+ ],
756
+ [
757
+ "Marshall Islands",
758
+ "mh",
759
+ "692"
760
+ ],
761
+ [
762
+ "Martinique",
763
+ "mq",
764
+ "596"
765
+ ],
766
+ [
767
+ "Mauritania",
768
+ "mr",
769
+ "222"
770
+ ],
771
+ [
772
+ "Mauritius",
773
+ "mu",
774
+ "230"
775
+ ],
776
+ [
777
+ "Mayotte",
778
+ "yt",
779
+ "262",
780
+ 1,
781
+ ["269", "639"]
782
+ ],
783
+ [
784
+ "Mexico",
785
+ "mx",
786
+ "52"
787
+ ],
788
+ [
789
+ "Micronesia",
790
+ "fm",
791
+ "691"
792
+ ],
793
+ [
794
+ "Moldova",
795
+ "md",
796
+ "373"
797
+ ],
798
+ [
799
+ "Monaco",
800
+ "mc",
801
+ "377"
802
+ ],
803
+ [
804
+ "Mongolia",
805
+ "mn",
806
+ "976"
807
+ ],
808
+ [
809
+ "Montenegro",
810
+ "me",
811
+ "382"
812
+ ],
813
+ [
814
+ "Montserrat",
815
+ "ms",
816
+ "1",
817
+ 16,
818
+ ["664"]
819
+ ],
820
+ [
821
+ "Morocco",
822
+ "ma",
823
+ "212",
824
+ 0
825
+ ],
826
+ [
827
+ "Mozambique",
828
+ "mz",
829
+ "258"
830
+ ],
831
+ [
832
+ "Myanmar (Burma)",
833
+ "mm",
834
+ "95"
835
+ ],
836
+ [
837
+ "Namibia",
838
+ "na",
839
+ "264"
840
+ ],
841
+ [
842
+ "Nauru",
843
+ "nr",
844
+ "674"
845
+ ],
846
+ [
847
+ "Nepal",
848
+ "np",
849
+ "977"
850
+ ],
851
+ [
852
+ "Netherlands",
853
+ "nl",
854
+ "31"
855
+ ],
856
+ [
857
+ "New Caledonia",
858
+ "nc",
859
+ "687"
860
+ ],
861
+ [
862
+ "New Zealand",
863
+ "nz",
864
+ "64"
865
+ ],
866
+ [
867
+ "Nicaragua",
868
+ "ni",
869
+ "505"
870
+ ],
871
+ [
872
+ "Niger",
873
+ "ne",
874
+ "227"
875
+ ],
876
+ [
877
+ "Nigeria",
878
+ "ng",
879
+ "234"
880
+ ],
881
+ [
882
+ "Niue",
883
+ "nu",
884
+ "683"
885
+ ],
886
+ [
887
+ "Norfolk Island",
888
+ "nf",
889
+ "672"
890
+ ],
891
+ [
892
+ "North Korea",
893
+ "kp",
894
+ "850"
895
+ ],
896
+ [
897
+ "North Macedonia",
898
+ "mk",
899
+ "389"
900
+ ],
901
+ [
902
+ "Northern Mariana Islands",
903
+ "mp",
904
+ "1",
905
+ 17,
906
+ ["670"]
907
+ ],
908
+ [
909
+ "Norway",
910
+ "no",
911
+ "47",
912
+ 0
913
+ ],
914
+ [
915
+ "Oman",
916
+ "om",
917
+ "968"
918
+ ],
919
+ [
920
+ "Pakistan",
921
+ "pk",
922
+ "92"
923
+ ],
924
+ [
925
+ "Palau",
926
+ "pw",
927
+ "680"
928
+ ],
929
+ [
930
+ "Palestine",
931
+ "ps",
932
+ "970"
933
+ ],
934
+ [
935
+ "Panama",
936
+ "pa",
937
+ "507"
938
+ ],
939
+ [
940
+ "Papua New Guinea",
941
+ "pg",
942
+ "675"
943
+ ],
944
+ [
945
+ "Paraguay",
946
+ "py",
947
+ "595"
948
+ ],
949
+ [
950
+ "Peru",
951
+ "pe",
952
+ "51"
953
+ ],
954
+ [
955
+ "Philippines",
956
+ "ph",
957
+ "63"
958
+ ],
959
+ [
960
+ "Poland",
961
+ "pl",
962
+ "48"
963
+ ],
964
+ [
965
+ "Portugal",
966
+ "pt",
967
+ "351"
968
+ ],
969
+ [
970
+ "Puerto Rico",
971
+ "pr",
972
+ "1",
973
+ 3,
974
+ ["787", "939"]
975
+ ],
976
+ [
977
+ "Qatar",
978
+ "qa",
979
+ "974"
980
+ ],
981
+ [
982
+ "R\xE9union",
983
+ "re",
984
+ "262",
985
+ 0
986
+ ],
987
+ [
988
+ "Romania",
989
+ "ro",
990
+ "40"
991
+ ],
992
+ [
993
+ "Russia",
994
+ "ru",
995
+ "7",
996
+ 0
997
+ ],
998
+ [
999
+ "Rwanda",
1000
+ "rw",
1001
+ "250"
1002
+ ],
1003
+ [
1004
+ "Samoa",
1005
+ "ws",
1006
+ "685"
1007
+ ],
1008
+ [
1009
+ "San Marino",
1010
+ "sm",
1011
+ "378"
1012
+ ],
1013
+ [
1014
+ "S\xE3o Tom\xE9 & Pr\xEDncipe",
1015
+ "st",
1016
+ "239"
1017
+ ],
1018
+ [
1019
+ "Saudi Arabia",
1020
+ "sa",
1021
+ "966"
1022
+ ],
1023
+ [
1024
+ "Senegal",
1025
+ "sn",
1026
+ "221"
1027
+ ],
1028
+ [
1029
+ "Serbia",
1030
+ "rs",
1031
+ "381"
1032
+ ],
1033
+ [
1034
+ "Seychelles",
1035
+ "sc",
1036
+ "248"
1037
+ ],
1038
+ [
1039
+ "Sierra Leone",
1040
+ "sl",
1041
+ "232"
1042
+ ],
1043
+ [
1044
+ "Singapore",
1045
+ "sg",
1046
+ "65"
1047
+ ],
1048
+ [
1049
+ "Sint Maarten",
1050
+ "sx",
1051
+ "1",
1052
+ 21,
1053
+ ["721"]
1054
+ ],
1055
+ [
1056
+ "Slovakia",
1057
+ "sk",
1058
+ "421"
1059
+ ],
1060
+ [
1061
+ "Slovenia",
1062
+ "si",
1063
+ "386"
1064
+ ],
1065
+ [
1066
+ "Solomon Islands",
1067
+ "sb",
1068
+ "677"
1069
+ ],
1070
+ [
1071
+ "Somalia",
1072
+ "so",
1073
+ "252"
1074
+ ],
1075
+ [
1076
+ "South Africa",
1077
+ "za",
1078
+ "27"
1079
+ ],
1080
+ [
1081
+ "South Korea",
1082
+ "kr",
1083
+ "82"
1084
+ ],
1085
+ [
1086
+ "South Sudan",
1087
+ "ss",
1088
+ "211"
1089
+ ],
1090
+ [
1091
+ "Spain",
1092
+ "es",
1093
+ "34"
1094
+ ],
1095
+ [
1096
+ "Sri Lanka",
1097
+ "lk",
1098
+ "94"
1099
+ ],
1100
+ [
1101
+ "St Barth\xE9lemy",
1102
+ "bl",
1103
+ "590",
1104
+ 1
1105
+ ],
1106
+ [
1107
+ "St Helena",
1108
+ "sh",
1109
+ "290"
1110
+ ],
1111
+ [
1112
+ "St Kitts & Nevis",
1113
+ "kn",
1114
+ "1",
1115
+ 18,
1116
+ ["869"]
1117
+ ],
1118
+ [
1119
+ "St Lucia",
1120
+ "lc",
1121
+ "1",
1122
+ 19,
1123
+ ["758"]
1124
+ ],
1125
+ [
1126
+ "St Martin",
1127
+ "mf",
1128
+ "590",
1129
+ 2
1130
+ ],
1131
+ [
1132
+ "St Pierre & Miquelon",
1133
+ "pm",
1134
+ "508"
1135
+ ],
1136
+ [
1137
+ "St Vincent & Grenadines",
1138
+ "vc",
1139
+ "1",
1140
+ 20,
1141
+ ["784"]
1142
+ ],
1143
+ [
1144
+ "Sudan",
1145
+ "sd",
1146
+ "249"
1147
+ ],
1148
+ [
1149
+ "Suriname",
1150
+ "sr",
1151
+ "597"
1152
+ ],
1153
+ [
1154
+ "Svalbard & Jan Mayen",
1155
+ "sj",
1156
+ "47",
1157
+ 1,
1158
+ ["79"]
1159
+ ],
1160
+ [
1161
+ "Sweden",
1162
+ "se",
1163
+ "46"
1164
+ ],
1165
+ [
1166
+ "Switzerland",
1167
+ "ch",
1168
+ "41"
1169
+ ],
1170
+ [
1171
+ "Syria",
1172
+ "sy",
1173
+ "963"
1174
+ ],
1175
+ [
1176
+ "Taiwan",
1177
+ "tw",
1178
+ "886"
1179
+ ],
1180
+ [
1181
+ "Tajikistan",
1182
+ "tj",
1183
+ "992"
1184
+ ],
1185
+ [
1186
+ "Tanzania",
1187
+ "tz",
1188
+ "255"
1189
+ ],
1190
+ [
1191
+ "Thailand",
1192
+ "th",
1193
+ "66"
1194
+ ],
1195
+ [
1196
+ "Timor-Leste",
1197
+ "tl",
1198
+ "670"
1199
+ ],
1200
+ [
1201
+ "Togo",
1202
+ "tg",
1203
+ "228"
1204
+ ],
1205
+ [
1206
+ "Tokelau",
1207
+ "tk",
1208
+ "690"
1209
+ ],
1210
+ [
1211
+ "Tonga",
1212
+ "to",
1213
+ "676"
1214
+ ],
1215
+ [
1216
+ "Trinidad & Tobago",
1217
+ "tt",
1218
+ "1",
1219
+ 22,
1220
+ ["868"]
1221
+ ],
1222
+ [
1223
+ "Tunisia",
1224
+ "tn",
1225
+ "216"
1226
+ ],
1227
+ [
1228
+ "Turkey",
1229
+ "tr",
1230
+ "90"
1231
+ ],
1232
+ [
1233
+ "Turkmenistan",
1234
+ "tm",
1235
+ "993"
1236
+ ],
1237
+ [
1238
+ "Turks & Caicos Islands",
1239
+ "tc",
1240
+ "1",
1241
+ 23,
1242
+ ["649"]
1243
+ ],
1244
+ [
1245
+ "Tuvalu",
1246
+ "tv",
1247
+ "688"
1248
+ ],
1249
+ [
1250
+ "Uganda",
1251
+ "ug",
1252
+ "256"
1253
+ ],
1254
+ [
1255
+ "Ukraine",
1256
+ "ua",
1257
+ "380"
1258
+ ],
1259
+ [
1260
+ "United Arab Emirates",
1261
+ "ae",
1262
+ "971"
1263
+ ],
1264
+ [
1265
+ "United Kingdom",
1266
+ "gb",
1267
+ "44",
1268
+ 0
1269
+ ],
1270
+ [
1271
+ "United States",
1272
+ "us",
1273
+ "1",
1274
+ 0
1275
+ ],
1276
+ [
1277
+ "Uruguay",
1278
+ "uy",
1279
+ "598"
1280
+ ],
1281
+ [
1282
+ "US Virgin Islands",
1283
+ "vi",
1284
+ "1",
1285
+ 24,
1286
+ ["340"]
1287
+ ],
1288
+ [
1289
+ "Uzbekistan",
1290
+ "uz",
1291
+ "998"
1292
+ ],
1293
+ [
1294
+ "Vanuatu",
1295
+ "vu",
1296
+ "678"
1297
+ ],
1298
+ [
1299
+ "Vatican City",
1300
+ "va",
1301
+ "39",
1302
+ 1,
1303
+ ["06698"]
1304
+ ],
1305
+ [
1306
+ "Venezuela",
1307
+ "ve",
1308
+ "58"
1309
+ ],
1310
+ [
1311
+ "Vietnam",
1312
+ "vn",
1313
+ "84"
1314
+ ],
1315
+ [
1316
+ "Wallis & Futuna",
1317
+ "wf",
1318
+ "681"
1319
+ ],
1320
+ [
1321
+ "Western Sahara",
1322
+ "eh",
1323
+ "212",
1324
+ 1,
1325
+ ["5288", "5289"]
1326
+ ],
1327
+ [
1328
+ "Yemen",
1329
+ "ye",
1330
+ "967"
1331
+ ],
1332
+ [
1333
+ "Zambia",
1334
+ "zm",
1335
+ "260"
1336
+ ],
1337
+ [
1338
+ "Zimbabwe",
1339
+ "zw",
1340
+ "263"
1341
+ ],
1342
+ [
1343
+ "\xC5land Islands",
1344
+ "ax",
1345
+ "358",
1346
+ 1,
1347
+ ["18"]
1348
+ ]
1349
+ ];
1350
+ var allCountries = [];
1351
+ for (let i = 0; i < rawCountryData.length; i++) {
1352
+ const c = rawCountryData[i];
1353
+ allCountries[i] = {
1354
+ name: c[0],
1355
+ iso2: c[1],
1356
+ dialCode: c[2],
1357
+ priority: c[3] || 0,
1358
+ areaCodes: c[4] || null,
1359
+ nodeById: {}
1360
+ };
1361
+ }
1362
+ var data_default = allCountries;
1363
+
1364
+ // src/js/intlTelInput.ts
1365
+ var id = 0;
1366
+ var defaults = {
1367
+ // whether or not to allow the dropdown
1368
+ allowDropdown: true,
1369
+ // add a placeholder in the input with an example number for the selected country
1370
+ autoPlaceholder: "polite",
1371
+ // add a country search input at the top of the dropdown
1372
+ countrySearch: true,
1373
+ // modify the parentClass
1374
+ containerClass: "",
1375
+ // modify the auto placeholder
1376
+ customPlaceholder: null,
1377
+ // append menu to specified element
1378
+ dropdownContainer: null,
1379
+ // don't display these countries
1380
+ excludeCountries: [],
1381
+ // fix the dropdown width to the input width (rather than being as wide as the longest country name)
1382
+ fixDropdownWidth: true,
1383
+ // format the number as the user types
1384
+ formatAsYouType: true,
1385
+ // format the input value during initialisation and on setNumber
1386
+ formatOnDisplay: true,
1387
+ // geoIp lookup function
1388
+ geoIpLookup: null,
1389
+ // inject a hidden input with the name returned from this function, and on submit, populate it with the result of getNumber
1390
+ hiddenInput: null,
1391
+ // internationalise the plugin text e.g. search input placeholder, country names
1392
+ i18n: {},
1393
+ // initial country
1394
+ initialCountry: "",
1395
+ // national vs international formatting for numbers e.g. placeholders and displaying existing numbers
1396
+ nationalMode: true,
1397
+ // display only these countries
1398
+ onlyCountries: [],
1399
+ // number type to use for placeholders
1400
+ placeholderNumberType: "MOBILE",
1401
+ // the countries at the top of the list
1402
+ preferredCountries: [],
1403
+ // option to hide the flags - must be used with showSelectedDialCode, or allowDropdown=false
1404
+ showFlags: true,
1405
+ // display the international dial code next to the selected flag
1406
+ showSelectedDialCode: false,
1407
+ // only allow certain chars e.g. a plus followed by numeric digits, and cap at max valid length
1408
+ strictMode: false,
1409
+ // use full screen popup instead of dropdown for country list
1410
+ useFullscreenPopup: typeof navigator !== "undefined" && typeof window !== "undefined" ? (
1411
+ // we cannot just test screen size as some smartphones/website meta tags will report desktop
1412
+ // resolutions
1413
+ // Note: to target Android Mobiles (and not Tablets), we must find 'Android' and 'Mobile'
1414
+ /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
1415
+ navigator.userAgent
1416
+ ) || window.innerWidth <= 500
1417
+ ) : false,
1418
+ // specify the path to the libphonenumber script to enable validation/formatting
1419
+ utilsScript: ""
1420
+ };
1421
+ var regionlessNanpNumbers = [
1422
+ "800",
1423
+ "822",
1424
+ "833",
1425
+ "844",
1426
+ "855",
1427
+ "866",
1428
+ "877",
1429
+ "880",
1430
+ "881",
1431
+ "882",
1432
+ "883",
1433
+ "884",
1434
+ "885",
1435
+ "886",
1436
+ "887",
1437
+ "888",
1438
+ "889"
1439
+ ];
1440
+ var getNumeric = (s) => s.replace(/\D/g, "");
1441
+ var normaliseString = (s = "") => s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
1442
+ var toggleClass = (el, className, shouldHaveClass) => {
1443
+ if (shouldHaveClass && !el.classList.contains(className)) {
1444
+ el.classList.add(className);
1445
+ } else if (!shouldHaveClass && el.classList.contains(className)) {
1446
+ el.classList.remove(className);
1447
+ }
1448
+ };
1449
+ var isRegionlessNanp = (number) => {
1450
+ const numeric = getNumeric(number);
1451
+ if (numeric.charAt(0) === "1") {
1452
+ const areaCode = numeric.substr(1, 3);
1453
+ return regionlessNanpNumbers.indexOf(areaCode) !== -1;
1454
+ }
1455
+ return false;
1456
+ };
1457
+ var countryNameSort = (a, b) => {
1458
+ if (a.name < b.name) {
1459
+ return -1;
1460
+ }
1461
+ if (a.name > b.name) {
1462
+ return 1;
1463
+ }
1464
+ return 0;
1465
+ };
1466
+ var translateCursorPosition = (relevantChars, formattedValue, prevCaretPos, isDeleteForwards) => {
1467
+ if (prevCaretPos === 0 && !isDeleteForwards) {
1468
+ return 0;
1469
+ }
1470
+ let count = 0;
1471
+ for (let i = 0; i < formattedValue.length; i++) {
1472
+ if (/[+0-9]/.test(formattedValue[i])) {
1473
+ count++;
1474
+ }
1475
+ if (count === relevantChars && !isDeleteForwards) {
1476
+ return i + 1;
1477
+ }
1478
+ if (isDeleteForwards && count === relevantChars + 1) {
1479
+ return i;
1480
+ }
1481
+ }
1482
+ return formattedValue.length;
1483
+ };
1484
+ var createEl = (name, attrs, container) => {
1485
+ const el = document.createElement(name);
1486
+ if (attrs) {
1487
+ Object.entries(attrs).forEach(([key, value]) => el.setAttribute(key, value));
1488
+ }
1489
+ if (container) {
1490
+ container.appendChild(el);
1491
+ }
1492
+ return el;
1493
+ };
1494
+ var forEachInstance = (method) => {
1495
+ const { instances } = window.intlTelInputGlobals;
1496
+ Object.values(instances).forEach((instance) => instance[method]());
1497
+ };
1498
+ var Iti = class {
1499
+ // can't be private as it's called from intlTelInput convenience wrapper
1500
+ id;
1501
+ // not private!
1502
+ promise;
1503
+ // private
1504
+ telInput;
1505
+ activeItem;
1506
+ highlightedItem;
1507
+ options;
1508
+ hadInitialPlaceholder;
1509
+ isRTL;
1510
+ selectedCountryData;
1511
+ countries;
1512
+ dialCodeMaxLen;
1513
+ dialCodeToIso2Map;
1514
+ dialCodes;
1515
+ preferredCountries;
1516
+ countryContainer;
1517
+ selectedCountry;
1518
+ selectedCountryInner;
1519
+ selectedCountryA11yText;
1520
+ selectedDialCode;
1521
+ dropdownArrow;
1522
+ dropdownContent;
1523
+ searchInput;
1524
+ searchResultsA11yText;
1525
+ countryList;
1526
+ dropdown;
1527
+ hiddenInput;
1528
+ hiddenInputCountry;
1529
+ maxCoreNumberLength;
1530
+ defaultCountry;
1531
+ _handleHiddenInputSubmit;
1532
+ _handleLabelClick;
1533
+ _handleClickSelectedCountry;
1534
+ _handleCountryContainerKeydown;
1535
+ _handleInputEvent;
1536
+ _handleKeydownEvent;
1537
+ _handleWindowScroll;
1538
+ _handleMouseoverCountryList;
1539
+ _handleClickCountryList;
1540
+ _handleClickOffToClose;
1541
+ _handleKeydownOnDropdown;
1542
+ _handleSearchChange;
1543
+ resolveAutoCountryPromise;
1544
+ rejectAutoCountryPromise;
1545
+ resolveUtilsScriptPromise;
1546
+ rejectUtilsScriptPromise;
1547
+ constructor(input, customOptions = {}) {
1548
+ this.id = id++;
1549
+ this.telInput = input;
1550
+ this.activeItem = null;
1551
+ this.highlightedItem = null;
1552
+ this.options = Object.assign({}, defaults, customOptions);
1553
+ this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder"));
1554
+ }
1555
+ // can't be private as it's called from intlTelInput convenience wrapper
1556
+ _init() {
1557
+ if (this.options.useFullscreenPopup) {
1558
+ this.options.fixDropdownWidth = false;
1559
+ }
1560
+ if (this.options.countrySearch && !this.options.useFullscreenPopup) {
1561
+ this.options.fixDropdownWidth = true;
1562
+ }
1563
+ const forceShowFlags = this.options.allowDropdown && !this.options.showSelectedDialCode;
1564
+ if (!this.options.showFlags && forceShowFlags) {
1565
+ this.options.showFlags = true;
1566
+ }
1567
+ if (this.options.useFullscreenPopup && !this.options.dropdownContainer) {
1568
+ this.options.dropdownContainer = document.body;
1569
+ }
1570
+ this.isRTL = !!this.telInput.closest("[dir=rtl]");
1571
+ const autoCountryPromise = new Promise((resolve, reject) => {
1572
+ this.resolveAutoCountryPromise = resolve;
1573
+ this.rejectAutoCountryPromise = reject;
1574
+ });
1575
+ const utilsScriptPromise = new Promise((resolve, reject) => {
1576
+ this.resolveUtilsScriptPromise = resolve;
1577
+ this.rejectUtilsScriptPromise = reject;
1578
+ });
1579
+ this.promise = Promise.all([autoCountryPromise, utilsScriptPromise]);
1580
+ this.selectedCountryData = {};
1581
+ this._processCountryData();
1582
+ this._generateMarkup();
1583
+ this._setInitialState();
1584
+ this._initListeners();
1585
+ this._initRequests();
1586
+ }
1587
+ //********************
1588
+ //* PRIVATE METHODS
1589
+ //********************
1590
+ // prepare all of the country data, including onlyCountries, excludeCountries and
1591
+ // preferredCountries options
1592
+ _processCountryData() {
1593
+ this._processAllCountries();
1594
+ this._processDialCodes();
1595
+ this._processPreferredCountries();
1596
+ this._translateCountryNames();
1597
+ if (this.options.onlyCountries.length || this.options.i18n) {
1598
+ this.countries.sort(countryNameSort);
1599
+ }
1600
+ }
1601
+ // add a dial code to this.dialCodeToIso2Map
1602
+ _addToDialCodeMap(iso2, dialCode, priority) {
1603
+ if (dialCode.length > this.dialCodeMaxLen) {
1604
+ this.dialCodeMaxLen = dialCode.length;
1605
+ }
1606
+ if (!this.dialCodeToIso2Map.hasOwnProperty(dialCode)) {
1607
+ this.dialCodeToIso2Map[dialCode] = [];
1608
+ }
1609
+ for (let i = 0; i < this.dialCodeToIso2Map[dialCode].length; i++) {
1610
+ if (this.dialCodeToIso2Map[dialCode][i] === iso2) {
1611
+ return;
39
1612
  }
40
- "use strict";
41
- function ownKeys(object, enumerableOnly) {
42
- var keys = Object.keys(object);
43
- if (Object.getOwnPropertySymbols) {
44
- var symbols = Object.getOwnPropertySymbols(object);
45
- enumerableOnly && (symbols = symbols.filter(function(sym) {
46
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
47
- })), keys.push.apply(keys, symbols);
48
- }
49
- return keys;
1613
+ }
1614
+ const index = priority !== void 0 ? priority : this.dialCodeToIso2Map[dialCode].length;
1615
+ this.dialCodeToIso2Map[dialCode][index] = iso2;
1616
+ }
1617
+ // process onlyCountries or excludeCountries array if present
1618
+ _processAllCountries() {
1619
+ const { onlyCountries, excludeCountries } = this.options;
1620
+ if (onlyCountries.length) {
1621
+ const lowerCaseOnlyCountries = onlyCountries.map(
1622
+ (country) => country.toLowerCase()
1623
+ );
1624
+ this.countries = data_default.filter(
1625
+ (country) => lowerCaseOnlyCountries.indexOf(country.iso2) > -1
1626
+ );
1627
+ } else if (excludeCountries.length) {
1628
+ const lowerCaseExcludeCountries = excludeCountries.map(
1629
+ (country) => country.toLowerCase()
1630
+ );
1631
+ this.countries = data_default.filter(
1632
+ (country) => lowerCaseExcludeCountries.indexOf(country.iso2) === -1
1633
+ );
1634
+ } else {
1635
+ this.countries = data_default;
1636
+ }
1637
+ }
1638
+ // Translate Countries by object literal provided on config
1639
+ _translateCountryNames() {
1640
+ for (let i = 0; i < this.countries.length; i++) {
1641
+ const iso2 = this.countries[i].iso2.toLowerCase();
1642
+ if (this.options.i18n.hasOwnProperty(iso2)) {
1643
+ this.countries[i].name = this.options.i18n[iso2];
1644
+ }
1645
+ }
1646
+ }
1647
+ // generate this.dialCodes and this.dialCodeToIso2Map
1648
+ _processDialCodes() {
1649
+ this.dialCodes = {};
1650
+ this.dialCodeMaxLen = 0;
1651
+ this.dialCodeToIso2Map = {};
1652
+ for (let i = 0; i < this.countries.length; i++) {
1653
+ const c = this.countries[i];
1654
+ if (!this.dialCodes[c.dialCode]) {
1655
+ this.dialCodes[c.dialCode] = true;
50
1656
  }
51
- function _objectSpread(target) {
52
- for (var i = 1; i < arguments.length; i++) {
53
- var source = null != arguments[i] ? arguments[i] : {};
54
- i % 2 ? ownKeys(Object(source), !0).forEach(function(key) {
55
- _defineProperty(target, key, source[key]);
56
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
57
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
58
- });
1657
+ this._addToDialCodeMap(c.iso2, c.dialCode, c.priority);
1658
+ }
1659
+ for (let i = 0; i < this.countries.length; i++) {
1660
+ const c = this.countries[i];
1661
+ if (c.areaCodes) {
1662
+ const rootIso2Code = this.dialCodeToIso2Map[c.dialCode][0];
1663
+ for (let j = 0; j < c.areaCodes.length; j++) {
1664
+ const areaCode = c.areaCodes[j];
1665
+ for (let k = 1; k < areaCode.length; k++) {
1666
+ const partialDialCode = c.dialCode + areaCode.substr(0, k);
1667
+ this._addToDialCodeMap(rootIso2Code, partialDialCode);
1668
+ this._addToDialCodeMap(c.iso2, partialDialCode);
59
1669
  }
60
- return target;
1670
+ this._addToDialCodeMap(c.iso2, c.dialCode + areaCode);
1671
+ }
61
1672
  }
62
- function _defineProperty(obj, key, value) {
63
- key = _toPropertyKey(key);
64
- if (key in obj) {
65
- Object.defineProperty(obj, key, {
66
- value: value,
67
- enumerable: true,
68
- configurable: true,
69
- writable: true
70
- });
71
- } else {
72
- obj[key] = value;
1673
+ }
1674
+ }
1675
+ // process preferred countries - iterate through the preferences, fetching the country data for
1676
+ // each one
1677
+ _processPreferredCountries() {
1678
+ this.preferredCountries = [];
1679
+ for (let i = 0; i < this.options.preferredCountries.length; i++) {
1680
+ const iso2 = this.options.preferredCountries[i].toLowerCase();
1681
+ const countryData = this._getCountryData(iso2, true);
1682
+ if (countryData) {
1683
+ this.preferredCountries.push(countryData);
1684
+ }
1685
+ }
1686
+ }
1687
+ // generate all of the markup for the plugin: the selected country overlay, and the dropdown
1688
+ _generateMarkup() {
1689
+ this.telInput.classList.add("iti__tel-input");
1690
+ if (!this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete"))) {
1691
+ this.telInput.setAttribute("autocomplete", "off");
1692
+ }
1693
+ const {
1694
+ allowDropdown,
1695
+ showSelectedDialCode,
1696
+ showFlags,
1697
+ containerClass,
1698
+ hiddenInput,
1699
+ dropdownContainer,
1700
+ fixDropdownWidth,
1701
+ useFullscreenPopup,
1702
+ countrySearch,
1703
+ i18n
1704
+ } = this.options;
1705
+ let parentClass = "iti";
1706
+ if (allowDropdown) {
1707
+ parentClass += " iti--allow-dropdown";
1708
+ }
1709
+ if (showSelectedDialCode) {
1710
+ parentClass += " iti--show-selected-dial-code";
1711
+ }
1712
+ if (showFlags) {
1713
+ parentClass += " iti--show-flags";
1714
+ }
1715
+ if (containerClass) {
1716
+ parentClass += ` ${containerClass}`;
1717
+ }
1718
+ if (!useFullscreenPopup) {
1719
+ parentClass += " iti--inline-dropdown";
1720
+ }
1721
+ const wrapper = createEl("div", { class: parentClass });
1722
+ this.telInput.parentNode?.insertBefore(wrapper, this.telInput);
1723
+ if (showFlags || showSelectedDialCode) {
1724
+ this.countryContainer = createEl(
1725
+ "div",
1726
+ { class: "iti__country-container" },
1727
+ wrapper
1728
+ );
1729
+ this.selectedCountry = createEl(
1730
+ "button",
1731
+ {
1732
+ type: "button",
1733
+ class: "iti__selected-country",
1734
+ ...allowDropdown && {
1735
+ "aria-expanded": "false",
1736
+ "aria-label": this.options.i18n.selectedCountryAriaLabel || "Selected country",
1737
+ "aria-haspopup": countrySearch ? "true" : "listbox",
1738
+ "aria-controls": countrySearch ? `iti-${this.id}__dropdown-content` : `iti-${this.id}__country-listbox`,
1739
+ ...countrySearch ? { role: "combobox" } : {}
73
1740
  }
74
- return obj;
1741
+ },
1742
+ this.countryContainer
1743
+ );
1744
+ this.selectedCountryInner = createEl("div", null, this.selectedCountry);
1745
+ this.selectedCountryA11yText = createEl(
1746
+ "span",
1747
+ { class: "iti__a11y-text" },
1748
+ this.selectedCountryInner
1749
+ );
1750
+ }
1751
+ wrapper.appendChild(this.telInput);
1752
+ if (this.selectedCountry && this.telInput.disabled) {
1753
+ this.selectedCountry.setAttribute("aria-disabled", "true");
1754
+ }
1755
+ if (showSelectedDialCode) {
1756
+ this.selectedDialCode = createEl(
1757
+ "div",
1758
+ { class: "iti__selected-dial-code" },
1759
+ this.selectedCountry
1760
+ );
1761
+ }
1762
+ if (allowDropdown) {
1763
+ if (!this.telInput.disabled) {
1764
+ this.selectedCountry.setAttribute("tabindex", "0");
75
1765
  }
76
- function _slicedToArray(arr, i) {
77
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
1766
+ this.dropdownArrow = createEl(
1767
+ "div",
1768
+ { class: "iti__arrow", "aria-hidden": "true" },
1769
+ this.selectedCountry
1770
+ );
1771
+ const extraClasses = fixDropdownWidth ? "" : "iti--flexible-dropdown-width";
1772
+ this.dropdownContent = createEl("div", {
1773
+ id: `iti-${this.id}__dropdown-content`,
1774
+ class: `iti__dropdown-content iti__hide ${extraClasses}`
1775
+ });
1776
+ if (countrySearch) {
1777
+ this.searchInput = createEl(
1778
+ "input",
1779
+ {
1780
+ type: "text",
1781
+ class: "iti__search-input",
1782
+ placeholder: i18n.searchPlaceholder || "Search",
1783
+ role: "combobox",
1784
+ "aria-expanded": "true",
1785
+ "aria-label": i18n.searchPlaceholder || "Search",
1786
+ "aria-controls": `iti-${this.id}__country-listbox`,
1787
+ "aria-autocomplete": "list",
1788
+ "autocomplete": "off"
1789
+ },
1790
+ this.dropdownContent
1791
+ );
1792
+ this.searchResultsA11yText = createEl(
1793
+ "span",
1794
+ { class: "iti__a11y-text" },
1795
+ this.dropdownContent
1796
+ );
78
1797
  }
79
- function _nonIterableRest() {
80
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1798
+ this.countryList = createEl(
1799
+ "ul",
1800
+ {
1801
+ class: "iti__country-list",
1802
+ id: `iti-${this.id}__country-listbox`,
1803
+ role: "listbox",
1804
+ "aria-label": i18n.countryListAriaLabel || "List of countries"
1805
+ },
1806
+ this.dropdownContent
1807
+ );
1808
+ if (this.preferredCountries.length && !countrySearch) {
1809
+ this._appendListItems(this.preferredCountries, "iti__preferred", true);
1810
+ createEl(
1811
+ "li",
1812
+ {
1813
+ class: "iti__divider",
1814
+ "aria-hidden": "true"
1815
+ },
1816
+ this.countryList
1817
+ );
81
1818
  }
82
- function _unsupportedIterableToArray(o, minLen) {
83
- if (!o) return;
84
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
85
- var n = Object.prototype.toString.call(o).slice(8, -1);
86
- if (n === "Object" && o.constructor) n = o.constructor.name;
87
- if (n === "Map" || n === "Set") return Array.from(o);
88
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
1819
+ this._appendListItems(this.countries, "iti__standard");
1820
+ if (countrySearch) {
1821
+ this._updateSearchResultsText();
89
1822
  }
90
- function _arrayLikeToArray(arr, len) {
91
- if (len == null || len > arr.length) len = arr.length;
92
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
93
- return arr2;
1823
+ if (dropdownContainer) {
1824
+ let dropdownClasses = "iti iti--container";
1825
+ if (useFullscreenPopup) {
1826
+ dropdownClasses += " iti--fullscreen-popup";
1827
+ } else {
1828
+ dropdownClasses += " iti--inline-dropdown";
1829
+ }
1830
+ if (countrySearch) {
1831
+ dropdownClasses += " iti--country-search";
1832
+ }
1833
+ this.dropdown = createEl("div", { class: dropdownClasses });
1834
+ this.dropdown.appendChild(this.dropdownContent);
1835
+ } else {
1836
+ this.countryContainer.appendChild(this.dropdownContent);
94
1837
  }
95
- function _iterableToArrayLimit(arr, i) {
96
- var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
97
- if (null != _i) {
98
- var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1;
99
- try {
100
- if (_x = (_i = _i.call(arr)).next, 0 === i) {
101
- if (Object(_i) !== _i) return;
102
- _n = !1;
103
- } else for (;!(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) ;
104
- } catch (err) {
105
- _d = !0, _e = err;
106
- } finally {
107
- try {
108
- if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
109
- } finally {
110
- if (_d) throw _e;
111
- }
112
- }
113
- return _arr;
114
- }
1838
+ }
1839
+ if (hiddenInput) {
1840
+ const telInputName = this.telInput.getAttribute("name") || "";
1841
+ const names = hiddenInput(telInputName);
1842
+ if (names.phone) {
1843
+ this.hiddenInput = createEl("input", {
1844
+ type: "hidden",
1845
+ name: names.phone
1846
+ });
1847
+ wrapper.appendChild(this.hiddenInput);
115
1848
  }
116
- function _arrayWithHoles(arr) {
117
- if (Array.isArray(arr)) return arr;
1849
+ if (names.country) {
1850
+ this.hiddenInputCountry = createEl("input", {
1851
+ type: "hidden",
1852
+ name: names.country
1853
+ });
1854
+ wrapper.appendChild(this.hiddenInputCountry);
118
1855
  }
119
- function _classCallCheck(instance, Constructor) {
120
- if (!(instance instanceof Constructor)) {
121
- throw new TypeError("Cannot call a class as a function");
122
- }
1856
+ }
1857
+ }
1858
+ // for each of the passed countries: add a country <li> to the countryList <ul> container
1859
+ _appendListItems(countries, className, preferred) {
1860
+ for (let i = 0; i < countries.length; i++) {
1861
+ const c = countries[i];
1862
+ const idSuffix = preferred ? "-preferred" : "";
1863
+ const listItem = createEl(
1864
+ "li",
1865
+ {
1866
+ id: `iti-${this.id}__item-${c.iso2}${idSuffix}`,
1867
+ class: `iti__country ${className}`,
1868
+ tabindex: "-1",
1869
+ role: "option",
1870
+ "data-dial-code": c.dialCode,
1871
+ "data-country-code": c.iso2,
1872
+ "aria-selected": "false"
1873
+ },
1874
+ this.countryList
1875
+ );
1876
+ c.nodeById[this.id] = listItem;
1877
+ let content = "";
1878
+ if (this.options.showFlags) {
1879
+ content += `<div class='iti__flag-box'><div class='iti__flag iti__${c.iso2}'></div></div>`;
123
1880
  }
124
- function _defineProperties(target, props) {
125
- for (var i = 0; i < props.length; i++) {
126
- var descriptor = props[i];
127
- descriptor.enumerable = descriptor.enumerable || false;
128
- descriptor.configurable = true;
129
- if ("value" in descriptor) descriptor.writable = true;
130
- Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
131
- }
1881
+ content += `<span class='iti__country-name'>${c.name}</span>`;
1882
+ content += `<span class='iti__dial-code'>+${c.dialCode}</span>`;
1883
+ listItem.insertAdjacentHTML("beforeend", content);
1884
+ }
1885
+ }
1886
+ // set the initial state of the input value and the selected country by:
1887
+ // 1. extracting a dial code from the given number
1888
+ // 2. using explicit initialCountry
1889
+ // 3. picking the first preferred country
1890
+ // 4. picking the first country
1891
+ _setInitialState(overrideAutoCountry = false) {
1892
+ const attributeValue = this.telInput.getAttribute("value");
1893
+ const inputValue = this.telInput.value;
1894
+ const useAttribute = attributeValue && attributeValue.charAt(0) === "+" && (!inputValue || inputValue.charAt(0) !== "+");
1895
+ const val = useAttribute ? attributeValue : inputValue;
1896
+ const dialCode = this._getDialCode(val);
1897
+ const isRegionlessNanpNumber = isRegionlessNanp(val);
1898
+ const { initialCountry } = this.options;
1899
+ if (dialCode && !isRegionlessNanpNumber) {
1900
+ this._updateCountryFromNumber(val);
1901
+ } else if (initialCountry !== "auto" || overrideAutoCountry) {
1902
+ const lowerInitialCountry = initialCountry ? initialCountry.toLowerCase() : "";
1903
+ const isValidInitialCountry = lowerInitialCountry && this._getCountryData(lowerInitialCountry, true);
1904
+ if (isValidInitialCountry) {
1905
+ this._setCountry(lowerInitialCountry);
1906
+ } else {
1907
+ if (dialCode && isRegionlessNanpNumber) {
1908
+ this._setCountry("us");
1909
+ } else {
1910
+ this._setCountry();
1911
+ }
132
1912
  }
133
- function _createClass(Constructor, protoProps, staticProps) {
134
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
135
- if (staticProps) _defineProperties(Constructor, staticProps);
136
- Object.defineProperty(Constructor, "prototype", {
137
- writable: false
138
- });
139
- return Constructor;
1913
+ }
1914
+ if (val) {
1915
+ this._updateValFromNumber(val);
1916
+ }
1917
+ }
1918
+ // initialise the main event listeners: input keyup, and click selected country
1919
+ _initListeners() {
1920
+ this._initTelInputListeners();
1921
+ if (this.options.allowDropdown) {
1922
+ this._initDropdownListeners();
1923
+ }
1924
+ if ((this.hiddenInput || this.hiddenInputCountry) && this.telInput.form) {
1925
+ this._initHiddenInputListener();
1926
+ }
1927
+ }
1928
+ // update hidden input on form submit
1929
+ _initHiddenInputListener() {
1930
+ this._handleHiddenInputSubmit = () => {
1931
+ if (this.hiddenInput) {
1932
+ this.hiddenInput.value = this.getNumber();
140
1933
  }
141
- function _toPropertyKey(arg) {
142
- var key = _toPrimitive(arg, "string");
143
- return typeof key === "symbol" ? key : String(key);
1934
+ if (this.hiddenInputCountry) {
1935
+ this.hiddenInputCountry.value = this.getSelectedCountryData().iso2 || "";
144
1936
  }
145
- function _toPrimitive(input, hint) {
146
- if (typeof input !== "object" || input === null) return input;
147
- var prim = input[Symbol.toPrimitive];
148
- if (prim !== undefined) {
149
- var res = prim.call(input, hint || "default");
150
- if (typeof res !== "object") return res;
151
- throw new TypeError("@@toPrimitive must return a primitive value.");
152
- }
153
- return (hint === "string" ? String : Number)(input);
1937
+ };
1938
+ this.telInput.form?.addEventListener(
1939
+ "submit",
1940
+ this._handleHiddenInputSubmit
1941
+ );
1942
+ }
1943
+ // initialise the dropdown listeners
1944
+ _initDropdownListeners() {
1945
+ this._handleLabelClick = (e) => {
1946
+ if (this.dropdownContent.classList.contains("iti__hide")) {
1947
+ this.telInput.focus();
1948
+ } else {
1949
+ e.preventDefault();
1950
+ }
1951
+ };
1952
+ const label = this.telInput.closest("label");
1953
+ if (label) {
1954
+ label.addEventListener("click", this._handleLabelClick);
1955
+ }
1956
+ this._handleClickSelectedCountry = () => {
1957
+ if (this.dropdownContent.classList.contains("iti__hide") && !this.telInput.disabled && !this.telInput.readOnly) {
1958
+ this._openDropdown();
154
1959
  }
155
- var intlTelInputGlobals = {
156
- getInstance: function getInstance(input) {
157
- var id = input.getAttribute("data-intl-tel-input-id");
158
- return window.intlTelInputGlobals.instances[id];
1960
+ };
1961
+ this.selectedCountry.addEventListener("click", this._handleClickSelectedCountry);
1962
+ this._handleCountryContainerKeydown = (e) => {
1963
+ const isDropdownHidden = this.dropdownContent.classList.contains("iti__hide");
1964
+ if (isDropdownHidden && ["ArrowUp", "ArrowDown", " ", "Enter"].includes(e.key)) {
1965
+ e.preventDefault();
1966
+ e.stopPropagation();
1967
+ this._openDropdown();
1968
+ }
1969
+ if (e.key === "Tab") {
1970
+ this._closeDropdown();
1971
+ }
1972
+ };
1973
+ this.countryContainer.addEventListener(
1974
+ "keydown",
1975
+ this._handleCountryContainerKeydown
1976
+ );
1977
+ }
1978
+ // init many requests: utils script / geo ip lookup
1979
+ _initRequests() {
1980
+ if (this.options.utilsScript && !window.intlTelInputUtils) {
1981
+ if (window.intlTelInputGlobals.documentReady()) {
1982
+ window.intlTelInputGlobals.loadUtils(this.options.utilsScript);
1983
+ } else {
1984
+ window.addEventListener("load", () => {
1985
+ window.intlTelInputGlobals.loadUtils(this.options.utilsScript);
1986
+ });
1987
+ }
1988
+ } else {
1989
+ this.resolveUtilsScriptPromise();
1990
+ }
1991
+ if (this.options.initialCountry === "auto" && !this.selectedCountryData.iso2) {
1992
+ this._loadAutoCountry();
1993
+ } else {
1994
+ this.resolveAutoCountryPromise();
1995
+ }
1996
+ }
1997
+ // perform the geo ip lookup
1998
+ _loadAutoCountry() {
1999
+ if (window.intlTelInputGlobals.autoCountry) {
2000
+ this.handleAutoCountry();
2001
+ } else if (!window.intlTelInputGlobals.startedLoadingAutoCountry) {
2002
+ window.intlTelInputGlobals.startedLoadingAutoCountry = true;
2003
+ if (typeof this.options.geoIpLookup === "function") {
2004
+ this.options.geoIpLookup(
2005
+ (iso2 = "") => {
2006
+ const iso2Lower = iso2.toLowerCase();
2007
+ const isValidIso2 = iso2Lower && this._getCountryData(iso2Lower, true);
2008
+ if (isValidIso2) {
2009
+ window.intlTelInputGlobals.autoCountry = iso2Lower;
2010
+ setTimeout(() => forEachInstance("handleAutoCountry"));
2011
+ } else {
2012
+ this._setInitialState(true);
2013
+ forEachInstance("rejectAutoCountryPromise");
2014
+ }
159
2015
  },
160
- instances: {},
161
- // using a global like this allows us to mock it in the tests
162
- documentReady: function documentReady() {
163
- return document.readyState === "complete";
2016
+ () => {
2017
+ this._setInitialState(true);
2018
+ forEachInstance("rejectAutoCountryPromise");
2019
+ }
2020
+ );
2021
+ }
2022
+ }
2023
+ }
2024
+ // initialize the tel input listeners
2025
+ _initTelInputListeners() {
2026
+ const { strictMode, formatAsYouType } = this.options;
2027
+ let userOverrideFormatting = false;
2028
+ this._handleInputEvent = (e) => {
2029
+ if (this._updateCountryFromNumber(this.telInput.value)) {
2030
+ this._triggerCountryChange();
2031
+ }
2032
+ const isFormattingChar = e && e.data && /[^+0-9]/.test(e.data);
2033
+ const isPaste = e && e.inputType === "insertFromPaste" && this.telInput.value;
2034
+ if (isFormattingChar || isPaste && !strictMode) {
2035
+ userOverrideFormatting = true;
2036
+ } else if (!/[^+0-9]/.test(this.telInput.value)) {
2037
+ userOverrideFormatting = false;
2038
+ }
2039
+ if (formatAsYouType && !userOverrideFormatting) {
2040
+ const currentCaretPos = this.telInput.selectionStart || 0;
2041
+ const valueBeforeCaret = this.telInput.value.substring(0, currentCaretPos);
2042
+ const relevantCharsBeforeCaret = valueBeforeCaret.replace(/[^+0-9]/g, "").length;
2043
+ const isDeleteForwards = e && e.inputType === "deleteContentForward";
2044
+ const formattedValue = this._formatNumberAsYouType();
2045
+ const newCaretPos = translateCursorPosition(relevantCharsBeforeCaret, formattedValue, currentCaretPos, isDeleteForwards);
2046
+ this.telInput.value = formattedValue;
2047
+ this.telInput.setSelectionRange(newCaretPos, newCaretPos);
2048
+ }
2049
+ };
2050
+ this.telInput.addEventListener("input", this._handleInputEvent);
2051
+ if (strictMode) {
2052
+ this._handleKeydownEvent = (e) => {
2053
+ if (e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
2054
+ const isInitialPlus = this.telInput.selectionStart === 0 && e.key === "+";
2055
+ const isNumeric = /^[0-9]$/.test(e.key);
2056
+ const isAllowedChar = isInitialPlus || isNumeric;
2057
+ const fullNumber = this._getFullNumber();
2058
+ const coreNumber = window.intlTelInputUtils.getCoreNumber(fullNumber, this.selectedCountryData.iso2);
2059
+ const hasReachedMaxLength = this.maxCoreNumberLength && coreNumber.length >= this.maxCoreNumberLength;
2060
+ if (!isAllowedChar || hasReachedMaxLength) {
2061
+ e.preventDefault();
164
2062
  }
2063
+ }
165
2064
  };
166
- if (typeof window === "object") {
167
- window.intlTelInputGlobals = intlTelInputGlobals;
2065
+ this.telInput.addEventListener("keydown", this._handleKeydownEvent);
2066
+ }
2067
+ }
2068
+ // adhere to the input's maxlength attr
2069
+ _cap(number) {
2070
+ const max = parseInt(this.telInput.getAttribute("maxlength") || "", 10);
2071
+ return max && number.length > max ? number.substr(0, max) : number;
2072
+ }
2073
+ // trigger a custom event on the input
2074
+ _trigger(name) {
2075
+ const e = new Event(name, {
2076
+ bubbles: true,
2077
+ cancelable: true
2078
+ });
2079
+ this.telInput.dispatchEvent(e);
2080
+ }
2081
+ // open the dropdown
2082
+ _openDropdown() {
2083
+ const { fixDropdownWidth, countrySearch } = this.options;
2084
+ if (fixDropdownWidth) {
2085
+ this.dropdownContent.style.width = `${this.telInput.offsetWidth}px`;
2086
+ }
2087
+ this.dropdownContent.classList.remove("iti__hide");
2088
+ this.selectedCountry.setAttribute("aria-expanded", "true");
2089
+ this._setDropdownPosition();
2090
+ if (this.activeItem && !countrySearch) {
2091
+ this._highlightListItem(this.activeItem, false);
2092
+ this._scrollTo(this.activeItem, true);
2093
+ } else {
2094
+ const firstCountryItem = this.countryList.firstElementChild;
2095
+ if (firstCountryItem) {
2096
+ this._highlightListItem(firstCountryItem, false);
2097
+ this.countryList.scrollTop = 0;
2098
+ }
2099
+ if (countrySearch) {
2100
+ this.searchInput.focus();
2101
+ }
2102
+ }
2103
+ this._bindDropdownListeners();
2104
+ this.dropdownArrow.classList.add("iti__arrow--up");
2105
+ this._trigger("open:countrydropdown");
2106
+ }
2107
+ // decide if should position dropdown above or below input (depends on position within viewport, and scroll)
2108
+ _setDropdownPosition() {
2109
+ if (this.options.dropdownContainer) {
2110
+ this.options.dropdownContainer.appendChild(this.dropdown);
2111
+ }
2112
+ if (!this.options.useFullscreenPopup) {
2113
+ const pos = this.telInput.getBoundingClientRect();
2114
+ const windowTop = document.documentElement.scrollTop;
2115
+ const inputTop = pos.top + windowTop;
2116
+ const dropdownHeight = this.dropdownContent.offsetHeight;
2117
+ const dropdownFitsBelow = inputTop + this.telInput.offsetHeight + dropdownHeight < windowTop + window.innerHeight;
2118
+ const dropdownFitsAbove = inputTop - dropdownHeight > windowTop;
2119
+ const positionDropdownAboveInput = !this.options.countrySearch && !dropdownFitsBelow && dropdownFitsAbove;
2120
+ toggleClass(
2121
+ this.dropdownContent,
2122
+ "iti__dropdown-content--dropup",
2123
+ positionDropdownAboveInput
2124
+ );
2125
+ if (this.options.dropdownContainer) {
2126
+ const extraTop = positionDropdownAboveInput ? 0 : this.telInput.offsetHeight;
2127
+ this.dropdown.style.top = `${inputTop + extraTop}px`;
2128
+ this.dropdown.style.left = `${pos.left + document.body.scrollLeft}px`;
2129
+ this._handleWindowScroll = () => this._closeDropdown();
2130
+ window.addEventListener("scroll", this._handleWindowScroll);
2131
+ }
2132
+ }
2133
+ }
2134
+ // we only bind dropdown listeners when the dropdown is open
2135
+ _bindDropdownListeners() {
2136
+ this._handleMouseoverCountryList = (e) => {
2137
+ const listItem = e.target?.closest(".iti__country");
2138
+ if (listItem) {
2139
+ this._highlightListItem(listItem, false);
2140
+ }
2141
+ };
2142
+ this.countryList.addEventListener(
2143
+ "mouseover",
2144
+ this._handleMouseoverCountryList
2145
+ );
2146
+ this._handleClickCountryList = (e) => {
2147
+ const listItem = e.target?.closest(".iti__country");
2148
+ if (listItem) {
2149
+ this._selectListItem(listItem);
2150
+ }
2151
+ };
2152
+ this.countryList.addEventListener("click", this._handleClickCountryList);
2153
+ let isOpening = true;
2154
+ this._handleClickOffToClose = () => {
2155
+ if (!isOpening) {
2156
+ this._closeDropdown();
2157
+ }
2158
+ isOpening = false;
2159
+ };
2160
+ document.documentElement.addEventListener(
2161
+ "click",
2162
+ this._handleClickOffToClose
2163
+ );
2164
+ let query = "";
2165
+ let queryTimer = null;
2166
+ this._handleKeydownOnDropdown = (e) => {
2167
+ if (["ArrowUp", "ArrowDown", "Enter", "Escape"].includes(e.key)) {
2168
+ e.preventDefault();
2169
+ e.stopPropagation();
2170
+ if (e.key === "ArrowUp" || e.key === "ArrowDown") {
2171
+ this._handleUpDownKey(e.key);
2172
+ } else if (e.key === "Enter") {
2173
+ this._handleEnterKey();
2174
+ } else if (e.key === "Escape") {
2175
+ this._closeDropdown();
2176
+ }
2177
+ }
2178
+ if (!this.options.countrySearch && /^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(e.key)) {
2179
+ e.stopPropagation();
2180
+ if (queryTimer) {
2181
+ clearTimeout(queryTimer);
2182
+ }
2183
+ query += e.key.toLowerCase();
2184
+ this._searchForCountry(query);
2185
+ queryTimer = setTimeout(() => {
2186
+ query = "";
2187
+ }, 1e3);
168
2188
  }
169
- // these vars persist through all instances of the plugin
170
- var id = 0;
171
- var defaults = {
172
- // whether or not to allow the dropdown
173
- allowDropdown: true,
174
- // add a placeholder in the input with an example number for the selected country
175
- autoPlaceholder: "polite",
176
- // add a country search input at the top of the dropdown
177
- countrySearch: true,
178
- // modify the parentClass
179
- containerClass: "",
180
- // modify the auto placeholder
181
- customPlaceholder: null,
182
- // append menu to specified element
183
- dropdownContainer: null,
184
- // don't display these countries
185
- excludeCountries: [],
186
- // fix the dropdown width to the input width (rather than being as wide as the longest country name)
187
- fixDropdownWidth: true,
188
- // format the number as the user types
189
- formatAsYouType: true,
190
- // format the input value during initialisation and on setNumber
191
- formatOnDisplay: true,
192
- // geoIp lookup function
193
- geoIpLookup: null,
194
- // inject a hidden input with the name returned from this function, and on submit, populate it with the result of getNumber
195
- hiddenInput: null,
196
- // internationalise the plugin text e.g. search input placeholder, country names
197
- i18n: {},
198
- // initial country
199
- initialCountry: "",
200
- // national vs international formatting for numbers e.g. placeholders and displaying existing numbers
201
- nationalMode: true,
202
- // display only these countries
203
- onlyCountries: [],
204
- // number type to use for placeholders
205
- placeholderNumberType: "MOBILE",
206
- // the countries at the top of the list
207
- preferredCountries: [],
208
- // option to hide the flags - must be used with showSelectedDialCode, or allowDropdown=false
209
- showFlags: true,
210
- // display the international dial code next to the selected flag
211
- showSelectedDialCode: false,
212
- // only allow certain chars e.g. a plus followed by numeric digits, and cap at max valid length
213
- strictMode: false,
214
- // use full screen popup instead of dropdown for country list
215
- useFullscreenPopup: typeof navigator !== "undefined" && typeof window !== "undefined" ? // we cannot just test screen size as some smartphones/website meta tags will report desktop
216
- // resolutions
217
- // Note: to target Android Mobiles (and not Tablets), we must find 'Android' and 'Mobile'
218
- /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || window.innerWidth <= 500 : false,
219
- // specify the path to the libphonenumber script to enable validation/formatting
220
- utilsScript: ""
2189
+ };
2190
+ document.addEventListener("keydown", this._handleKeydownOnDropdown);
2191
+ if (this.options.countrySearch) {
2192
+ const doFilter = () => {
2193
+ const inputQuery = this.searchInput.value.trim();
2194
+ if (inputQuery) {
2195
+ this._filterCountries(inputQuery);
2196
+ } else {
2197
+ this._filterCountries("", true);
2198
+ }
221
2199
  };
222
- // https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#Non-geographic_area_codes
223
- var regionlessNanpNumbers = [ "800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889" ];
224
- // run a method on each instance of the plugin
225
- var forEachInstance = function forEachInstance(method) {
226
- var instances = window.intlTelInputGlobals.instances;
227
- Object.values(instances).forEach(function(instance) {
228
- return instance[method]();
229
- });
2200
+ let keyupTimer = null;
2201
+ this._handleSearchChange = () => {
2202
+ if (keyupTimer) {
2203
+ clearTimeout(keyupTimer);
2204
+ }
2205
+ keyupTimer = setTimeout(() => {
2206
+ doFilter();
2207
+ keyupTimer = null;
2208
+ }, 100);
230
2209
  };
231
- // this is our plugin class that we will create an instance of
232
- // eslint-disable-next-line no-unused-vars
233
- var Iti = /*#__PURE__*/ function() {
234
- function Iti(input) {
235
- var customOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
236
- _classCallCheck(this, Iti);
237
- this.id = id++;
238
- this.telInput = input;
239
- this.activeItem = null;
240
- this.highlightedItem = null;
241
- // process specified options / defaults
242
- this.options = Object.assign({}, defaults, customOptions);
243
- this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder"));
2210
+ this.searchInput.addEventListener("input", this._handleSearchChange);
2211
+ this.searchInput.addEventListener("click", (e) => e.stopPropagation());
2212
+ }
2213
+ }
2214
+ _filterCountries(query, isReset = false) {
2215
+ let isFirst = true;
2216
+ this.countryList.innerHTML = "";
2217
+ const normalisedQuery = normaliseString(query);
2218
+ for (let i = 0; i < this.countries.length; i++) {
2219
+ const c = this.countries[i];
2220
+ const normalisedCountryName = normaliseString(c.name);
2221
+ const fullDialCode = `+${c.dialCode}`;
2222
+ if (isReset || normalisedCountryName.includes(normalisedQuery) || fullDialCode.includes(normalisedQuery) || c.iso2.includes(normalisedQuery)) {
2223
+ const listItem = c.nodeById[this.id];
2224
+ if (listItem) {
2225
+ this.countryList.appendChild(listItem);
2226
+ }
2227
+ if (isFirst) {
2228
+ this._highlightListItem(listItem, false);
2229
+ isFirst = false;
2230
+ }
2231
+ }
2232
+ }
2233
+ this.countryList.scrollTop = 0;
2234
+ this._updateSearchResultsText();
2235
+ }
2236
+ // update search results text (for a11y)
2237
+ _updateSearchResultsText() {
2238
+ const { i18n } = this.options;
2239
+ const count = this.countryList.childElementCount;
2240
+ let searchText;
2241
+ if (count === 0) {
2242
+ searchText = i18n.zeroSearchResults || "No results found";
2243
+ } else if (count === 1) {
2244
+ searchText = i18n.oneSearchResult || "1 result found";
2245
+ } else {
2246
+ searchText = i18n.multipleSearchResults ? i18n.multipleSearchResults.replace("${count}", count.toString()) : `${count} results found`;
2247
+ }
2248
+ this.searchResultsA11yText.textContent = searchText;
2249
+ }
2250
+ // highlight the next/prev item in the list (and ensure it is visible)
2251
+ _handleUpDownKey(key) {
2252
+ let next = key === "ArrowUp" ? this.highlightedItem?.previousElementSibling : this.highlightedItem?.nextElementSibling;
2253
+ if (next) {
2254
+ if (next.classList.contains("iti__divider")) {
2255
+ next = key === "ArrowUp" ? next.previousElementSibling : next.nextElementSibling;
2256
+ }
2257
+ } else if (this.countryList.childElementCount > 1) {
2258
+ next = key === "ArrowUp" ? this.countryList.lastElementChild : this.countryList.firstElementChild;
2259
+ }
2260
+ if (next) {
2261
+ this._scrollTo(next, false);
2262
+ const doFocus = !this.options.countrySearch;
2263
+ this._highlightListItem(next, doFocus);
2264
+ }
2265
+ }
2266
+ // select the currently highlighted item
2267
+ _handleEnterKey() {
2268
+ if (this.highlightedItem) {
2269
+ this._selectListItem(this.highlightedItem);
2270
+ }
2271
+ }
2272
+ // find the first list item whose name starts with the query string
2273
+ _searchForCountry(query) {
2274
+ for (let i = 0; i < this.countries.length; i++) {
2275
+ const c = this.countries[i];
2276
+ const startsWith = c.name.substr(0, query.length).toLowerCase() === query;
2277
+ if (startsWith) {
2278
+ const listItem = c.nodeById[this.id];
2279
+ this._highlightListItem(listItem, false);
2280
+ this._scrollTo(listItem, true);
2281
+ break;
2282
+ }
2283
+ }
2284
+ }
2285
+ // update the input's value to the given val (format first if possible)
2286
+ // NOTE: this is called from _setInitialState, handleUtils and setNumber
2287
+ _updateValFromNumber(fullNumber) {
2288
+ let number = fullNumber;
2289
+ if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) {
2290
+ const useNational = this.options.nationalMode || number.charAt(0) !== "+" && !this.options.showSelectedDialCode;
2291
+ const { NATIONAL, INTERNATIONAL } = window.intlTelInputUtils.numberFormat;
2292
+ const format = useNational ? NATIONAL : INTERNATIONAL;
2293
+ number = window.intlTelInputUtils.formatNumber(
2294
+ number,
2295
+ this.selectedCountryData.iso2,
2296
+ format
2297
+ );
2298
+ }
2299
+ number = this._beforeSetNumber(number);
2300
+ this.telInput.value = number;
2301
+ }
2302
+ // check if need to select a new country based on the given number
2303
+ // Note: called from _setInitialState, keyup handler, setNumber
2304
+ _updateCountryFromNumber(fullNumber) {
2305
+ const plusIndex = fullNumber.indexOf("+");
2306
+ let number = plusIndex ? fullNumber.substring(plusIndex) : fullNumber;
2307
+ const selectedDialCode = this.selectedCountryData.dialCode;
2308
+ const isNanp = selectedDialCode === "1";
2309
+ if (number && isNanp && number.charAt(0) !== "+") {
2310
+ if (number.charAt(0) !== "1") {
2311
+ number = `1${number}`;
2312
+ }
2313
+ number = `+${number}`;
2314
+ }
2315
+ if (this.options.showSelectedDialCode && selectedDialCode && number.charAt(0) !== "+") {
2316
+ number = `+${selectedDialCode}${number}`;
2317
+ }
2318
+ const dialCode = this._getDialCode(number, true);
2319
+ const numeric = getNumeric(number);
2320
+ let iso2 = null;
2321
+ if (dialCode) {
2322
+ const iso2Codes = this.dialCodeToIso2Map[getNumeric(dialCode)];
2323
+ const alreadySelected = iso2Codes.indexOf(this.selectedCountryData.iso2) !== -1 && numeric.length <= dialCode.length - 1;
2324
+ const isRegionlessNanpNumber = selectedDialCode === "1" && isRegionlessNanp(numeric);
2325
+ if (!isRegionlessNanpNumber && !alreadySelected) {
2326
+ for (let j = 0; j < iso2Codes.length; j++) {
2327
+ if (iso2Codes[j]) {
2328
+ iso2 = iso2Codes[j];
2329
+ break;
244
2330
  }
245
- _createClass(Iti, [ {
246
- key: "_init",
247
- value: function _init() {
248
- var _this = this;
249
- // if showing fullscreen popup, do not fix the width
250
- if (this.options.useFullscreenPopup) {
251
- this.options.fixDropdownWidth = false;
252
- }
253
- // when search enabled, we must fix the width else it would change with different results
254
- if (this.options.countrySearch && !this.options.useFullscreenPopup) {
255
- this.options.fixDropdownWidth = true;
256
- }
257
- // force showFlags=true if there's a dropdown and we're not displaying the dial code,
258
- // as otherwise you just have a down arrow on it's own which doesn't make sense
259
- var forceShowFlags = this.options.allowDropdown && !this.options.showSelectedDialCode;
260
- if (!this.options.showFlags && forceShowFlags) {
261
- this.options.showFlags = true;
262
- }
263
- // on mobile, we want a full screen dropdown, so we must append it to the body
264
- if (this.options.useFullscreenPopup && !this.options.dropdownContainer) {
265
- this.options.dropdownContainer = document.body;
266
- }
267
- // check if input has one parent with RTL
268
- this.isRTL = !!this.telInput.closest("[dir=rtl]");
269
- // these promises get resolved when their individual requests complete
270
- // this way the dev can do something like iti.promise.then(...) to know when all requests are
271
- // complete
272
- var autoCountryPromise = new Promise(function(resolve, reject) {
273
- _this.resolveAutoCountryPromise = resolve;
274
- _this.rejectAutoCountryPromise = reject;
275
- });
276
- var utilsScriptPromise = new Promise(function(resolve, reject) {
277
- _this.resolveUtilsScriptPromise = resolve;
278
- _this.rejectUtilsScriptPromise = reject;
279
- });
280
- this.promise = Promise.all([ autoCountryPromise, utilsScriptPromise ]);
281
- // in various situations there could be no country selected initially, but we need to be able
282
- // to assume this variable exists
283
- this.selectedCountryData = {};
284
- // process all the data: onlyCountries, excludeCountries, preferredCountries etc
285
- this._processCountryData();
286
- // generate the markup
287
- this._generateMarkup();
288
- // set the initial state of the input value and the selected flag
289
- this._setInitialState();
290
- // start all of the event listeners: input keydown, selectedFlag click
291
- this._initListeners();
292
- // utils script, and auto country
293
- this._initRequests();
294
- }
295
- }, {
296
- key: "_processCountryData",
297
- value: function _processCountryData() {
298
- // process onlyCountries or excludeCountries array if present
299
- this._processAllCountries();
300
- // generate this.dialCodes and this.dialCodeToIso2Map
301
- this._processDialCodes();
302
- // process the preferredCountries
303
- this._processPreferredCountries();
304
- // translate country names according to i18n option
305
- this._translateCountryNames();
306
- // sort countries by name
307
- if (this.options.onlyCountries.length || this.options.i18n) {
308
- this.countries.sort(this._countryNameSort);
309
- }
310
- }
311
- }, {
312
- key: "_addToDialCodeMap",
313
- value: function _addToDialCodeMap(iso2, dialCode, priority) {
314
- if (dialCode.length > this.dialCodeMaxLen) {
315
- this.dialCodeMaxLen = dialCode.length;
316
- }
317
- if (!this.dialCodeToIso2Map.hasOwnProperty(dialCode)) {
318
- this.dialCodeToIso2Map[dialCode] = [];
319
- }
320
- // bail if we already have this country for this dialCode
321
- for (var i = 0; i < this.dialCodeToIso2Map[dialCode].length; i++) {
322
- if (this.dialCodeToIso2Map[dialCode][i] === iso2) {
323
- return;
324
- }
325
- }
326
- // check for undefined as 0 is falsy
327
- var index = priority !== undefined ? priority : this.dialCodeToIso2Map[dialCode].length;
328
- this.dialCodeToIso2Map[dialCode][index] = iso2;
329
- }
330
- }, {
331
- key: "_processAllCountries",
332
- value: function _processAllCountries() {
333
- if (this.options.onlyCountries.length) {
334
- var lowerCaseOnlyCountries = this.options.onlyCountries.map(function(country) {
335
- return country.toLowerCase();
336
- });
337
- this.countries = allCountries.filter(function(country) {
338
- return lowerCaseOnlyCountries.indexOf(country.iso2) > -1;
339
- });
340
- } else if (this.options.excludeCountries.length) {
341
- var lowerCaseExcludeCountries = this.options.excludeCountries.map(function(country) {
342
- return country.toLowerCase();
343
- });
344
- this.countries = allCountries.filter(function(country) {
345
- return lowerCaseExcludeCountries.indexOf(country.iso2) === -1;
346
- });
347
- } else {
348
- this.countries = allCountries;
349
- }
350
- }
351
- }, {
352
- key: "_translateCountryNames",
353
- value: function _translateCountryNames() {
354
- for (var i = 0; i < this.countries.length; i++) {
355
- var iso2 = this.countries[i].iso2.toLowerCase();
356
- if (this.options.i18n.hasOwnProperty(iso2)) {
357
- this.countries[i].name = this.options.i18n[iso2];
358
- }
359
- }
360
- }
361
- }, {
362
- key: "_countryNameSort",
363
- value: function _countryNameSort(a, b) {
364
- if (a.name < b.name) {
365
- return -1;
366
- }
367
- if (a.name > b.name) {
368
- return 1;
369
- }
370
- return 0;
371
- }
372
- }, {
373
- key: "_processDialCodes",
374
- value: function _processDialCodes() {
375
- // here we store just dial codes, where the key is the dial code, and the value is true
376
- // e.g. { 1: true, 7: true, 20: true, ... }
377
- this.dialCodes = {};
378
- this.dialCodeMaxLen = 0;
379
- // here we map dialCodes (inc both dialCode and dialCode+areaCode) to iso2 codes
380
- /* e.g.
381
- * {
382
- * 1: [ 'us', 'ca', ... ], # all NANP countries
383
- * 12: [ 'us', 'ca', ... ], # subset of NANP countries
384
- * 120: [ 'us', 'ca' ], # just US and Canada
385
- * 1204: [ 'ca' ], # only Canada
386
- * ...
387
- * }
388
- */
389
- this.dialCodeToIso2Map = {};
390
- // first: add dial codes
391
- for (var i = 0; i < this.countries.length; i++) {
392
- var c = this.countries[i];
393
- if (!this.dialCodes[c.dialCode]) {
394
- this.dialCodes[c.dialCode] = true;
395
- }
396
- this._addToDialCodeMap(c.iso2, c.dialCode, c.priority);
397
- }
398
- // next: add area codes
399
- // this is a second loop over countries, to make sure we have all of the "root" countries
400
- // already in the map, so that we can access them, as each time we add an area code substring
401
- // to the map, we also need to include the "root" country's code, as that also matches
402
- for (var _i = 0; _i < this.countries.length; _i++) {
403
- var _c = this.countries[_i];
404
- // area codes
405
- if (_c.areaCodes) {
406
- var rootIso2Code = this.dialCodeToIso2Map[_c.dialCode][0];
407
- // for each area code
408
- for (var j = 0; j < _c.areaCodes.length; j++) {
409
- var areaCode = _c.areaCodes[j];
410
- // for each digit in the area code to add all partial matches as well
411
- for (var k = 1; k < areaCode.length; k++) {
412
- var partialDialCode = _c.dialCode + areaCode.substr(0, k);
413
- // start with the root country, as that also matches this dial code
414
- this._addToDialCodeMap(rootIso2Code, partialDialCode);
415
- this._addToDialCodeMap(_c.iso2, partialDialCode);
416
- }
417
- // add the full area code
418
- this._addToDialCodeMap(_c.iso2, _c.dialCode + areaCode);
419
- }
420
- }
421
- }
422
- }
423
- }, {
424
- key: "_processPreferredCountries",
425
- value: function _processPreferredCountries() {
426
- this.preferredCountries = [];
427
- for (var i = 0; i < this.options.preferredCountries.length; i++) {
428
- var iso2 = this.options.preferredCountries[i].toLowerCase();
429
- var countryData = this._getCountryData(iso2, true);
430
- if (countryData) {
431
- this.preferredCountries.push(countryData);
432
- }
433
- }
434
- }
435
- }, {
436
- key: "_createEl",
437
- value: function _createEl(name, attrs, container) {
438
- var el = document.createElement(name);
439
- if (attrs) {
440
- Object.entries(attrs).forEach(function(_ref) {
441
- var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1];
442
- return el.setAttribute(key, value);
443
- });
444
- }
445
- if (container) {
446
- container.appendChild(el);
447
- }
448
- return el;
449
- }
450
- }, {
451
- key: "_generateMarkup",
452
- value: function _generateMarkup() {
453
- this.telInput.classList.add("iti__tel-input");
454
- // if autocomplete does not exist on the element and its form, then
455
- // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can
456
- // easily put the plugin in an inconsistent state e.g. the wrong flag selected for the
457
- // autocompleted number, which on submit could mean wrong number is saved
458
- if (!this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete"))) {
459
- this.telInput.setAttribute("autocomplete", "off");
460
- }
461
- 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;
462
- // containers (mostly for positioning)
463
- var parentClass = "iti";
464
- if (allowDropdown) {
465
- parentClass += " iti--allow-dropdown";
466
- }
467
- if (showSelectedDialCode) {
468
- parentClass += " iti--show-selected-dial-code";
469
- }
470
- if (showFlags) {
471
- parentClass += " iti--show-flags";
472
- }
473
- if (containerClass) {
474
- parentClass += " ".concat(containerClass);
475
- }
476
- if (!useFullscreenPopup) {
477
- parentClass += " iti--inline-dropdown";
478
- }
479
- var wrapper = this._createEl("div", {
480
- "class": parentClass
481
- });
482
- this.telInput.parentNode.insertBefore(wrapper, this.telInput);
483
- // if we're showing flags or dial codes, we need the flags container etc
484
- if (showFlags || showSelectedDialCode) {
485
- this.flagsContainer = this._createEl("div", {
486
- "class": "iti__flag-container"
487
- }, wrapper);
488
- // selected flag (displayed on left of input while allowDropdown is enabled, otherwise to right)
489
- // when countrySearch disabled: using Aria tags for "Select-Only Combobox Example"
490
- // https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/
491
- this.selectedFlag = this._createEl("div", _objectSpread({
492
- "class": "iti__selected-flag"
493
- }, allowDropdown && _objectSpread({
494
- role: "button",
495
- "aria-expanded": "false",
496
- "aria-label": this.options.i18n.selectedCountryAriaLabel || "Selected country",
497
- "aria-haspopup": countrySearch ? "true" : "listbox",
498
- "aria-controls": countrySearch ? "iti-".concat(this.id, "__dropdown-content") : "iti-".concat(this.id, "__country-listbox")
499
- }, countrySearch || {
500
- role: "combobox"
501
- })), this.flagsContainer);
502
- // we now include the selected flag element even when showFlags is disabled,
503
- // as need to show globe icon for showSelectedDialCode empty state
504
- this.selectedFlagInner = this._createEl("div", null, this.selectedFlag);
505
- this.selectedFlagA11yText = this._createEl("span", {
506
- "class": "iti__a11y-text"
507
- }, this.selectedFlagInner);
508
- }
509
- wrapper.appendChild(this.telInput);
510
- if (this.selectedFlag && this.telInput.disabled) {
511
- this.selectedFlag.setAttribute("aria-disabled", "true");
512
- }
513
- if (showSelectedDialCode) {
514
- this.selectedDialCode = this._createEl("div", {
515
- "class": "iti__selected-dial-code"
516
- }, this.selectedFlag);
517
- }
518
- if (allowDropdown) {
519
- if (!this.telInput.disabled) {
520
- // make element focusable and tab navigable
521
- this.selectedFlag.setAttribute("tabindex", "0");
522
- }
523
- this.dropdownArrow = this._createEl("div", {
524
- "class": "iti__arrow",
525
- "aria-hidden": "true"
526
- }, this.selectedFlag);
527
- var extraClasses = fixDropdownWidth ? "" : "iti--flexible-dropdown-width";
528
- this.dropdownContent = this._createEl("div", {
529
- id: "iti-".concat(this.id, "__dropdown-content"),
530
- "class": "iti__dropdown-content iti__hide ".concat(extraClasses)
531
- });
532
- if (countrySearch) {
533
- this.searchInput = this._createEl("input", {
534
- type: "text",
535
- "class": "iti__search-input",
536
- placeholder: i18n.searchPlaceholder || "Search",
537
- role: "combobox",
538
- "aria-expanded": "true",
539
- "aria-label": i18n.searchPlaceholder || "Search",
540
- "aria-controls": "iti-".concat(this.id, "__country-listbox"),
541
- "aria-autocomplete": "list",
542
- autocomplete: "off"
543
- }, this.dropdownContent);
544
- this.searchResultsA11yText = this._createEl("span", {
545
- "class": "iti__a11y-text"
546
- }, this.dropdownContent);
547
- }
548
- // country list: preferred countries, then divider, then all countries
549
- this.countryList = this._createEl("ul", {
550
- "class": "iti__country-list",
551
- id: "iti-".concat(this.id, "__country-listbox"),
552
- role: "listbox",
553
- "aria-label": i18n.countryListAriaLabel || "List of countries"
554
- }, this.dropdownContent);
555
- if (this.preferredCountries.length && !countrySearch) {
556
- this._appendListItems(this.preferredCountries, "iti__preferred", true);
557
- this._createEl("li", {
558
- "class": "iti__divider",
559
- "aria-hidden": "true"
560
- }, this.countryList);
561
- }
562
- this._appendListItems(this.countries, "iti__standard");
563
- if (countrySearch) {
564
- this._updateSearchResultsText();
565
- }
566
- // create dropdownContainer markup
567
- if (dropdownContainer) {
568
- var dropdownClasses = "iti iti--container";
569
- if (useFullscreenPopup) {
570
- dropdownClasses += " iti--fullscreen-popup";
571
- } else {
572
- dropdownClasses += " iti--inline-dropdown";
573
- }
574
- if (countrySearch) {
575
- dropdownClasses += " iti--country-search";
576
- }
577
- this.dropdown = this._createEl("div", {
578
- "class": dropdownClasses
579
- });
580
- this.dropdown.appendChild(this.dropdownContent);
581
- } else {
582
- this.flagsContainer.appendChild(this.dropdownContent);
583
- }
584
- }
585
- if (hiddenInput) {
586
- var telInputName = this.telInput.getAttribute("name");
587
- var names = hiddenInput(telInputName);
588
- if (names.phone) {
589
- // Create hidden input for the full international number
590
- this.hiddenInput = this._createEl("input", {
591
- type: "hidden",
592
- name: names.phone
593
- });
594
- wrapper.appendChild(this.hiddenInput);
595
- }
596
- if (names.country) {
597
- // Create hidden input for the selected country iso2 code
598
- this.hiddenInputCountry = this._createEl("input", {
599
- type: "hidden",
600
- name: names.country
601
- });
602
- wrapper.appendChild(this.hiddenInputCountry);
603
- }
604
- }
605
- }
606
- }, {
607
- key: "_appendListItems",
608
- value: function _appendListItems(countries, className, preferred) {
609
- for (var i = 0; i < countries.length; i++) {
610
- var c = countries[i];
611
- var idSuffix = preferred ? "-preferred" : "";
612
- var listItem = this._createEl("li", {
613
- id: "iti-".concat(this.id, "__item-").concat(c.iso2).concat(idSuffix),
614
- "class": "iti__country ".concat(className),
615
- tabindex: "-1",
616
- role: "option",
617
- "data-dial-code": c.dialCode,
618
- "data-country-code": c.iso2,
619
- "aria-selected": "false"
620
- }, this.countryList);
621
- // store this for later use e.g. country search filtering
622
- c.nodeById[this.id] = listItem;
623
- var content = "";
624
- // add the flag
625
- if (this.options.showFlags) {
626
- content += "<div class='iti__flag-box'><div class='iti__flag iti__".concat(c.iso2, "'></div></div>");
627
- }
628
- // and the country name and dial code
629
- content += "<span class='iti__country-name'>".concat(c.name, "</span>");
630
- content += "<span class='iti__dial-code'>+".concat(c.dialCode, "</span>");
631
- listItem.insertAdjacentHTML("beforeend", content);
632
- }
633
- }
634
- }, {
635
- key: "_setInitialState",
636
- value: function _setInitialState() {
637
- var overrideAutoCountry = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
638
- // fix firefox bug: when first load page (with input with value set to number with intl dial
639
- // code) and initialising plugin removes the dial code from the input, then refresh page,
640
- // and we try to init plugin again but this time on number without dial code so get grey flag
641
- var attributeValue = this.telInput.getAttribute("value");
642
- var inputValue = this.telInput.value;
643
- var useAttribute = attributeValue && attributeValue.charAt(0) === "+" && (!inputValue || inputValue.charAt(0) !== "+");
644
- var val = useAttribute ? attributeValue : inputValue;
645
- var dialCode = this._getDialCode(val);
646
- var isRegionlessNanp = this._isRegionlessNanp(val);
647
- var initialCountry = this.options.initialCountry;
648
- // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the
649
- // flag, else fall back to the default country
650
- if (dialCode && !isRegionlessNanp) {
651
- this._updateFlagFromNumber(val);
652
- } else if (initialCountry !== "auto" || overrideAutoCountry) {
653
- var lowerInitialCountry = initialCountry ? initialCountry.toLowerCase() : "";
654
- var isValidInitialCountry = lowerInitialCountry && this._getCountryData(lowerInitialCountry, true);
655
- // see if we should select a flag
656
- if (isValidInitialCountry) {
657
- this._setCountry(lowerInitialCountry);
658
- } else {
659
- if (dialCode && isRegionlessNanp) {
660
- // has intl dial code, is regionless nanp, and no initialCountry, so default to US
661
- this._setCountry("us");
662
- } else {
663
- // display the empty state (globe icon)
664
- this._setCountry();
665
- }
666
- }
667
- }
668
- // NOTE: if initialCountry is set to auto, that will be handled separately
669
- // format - note this wont be run after _updateDialCode as that's only called if no val
670
- if (val) {
671
- this._updateValFromNumber(val);
672
- }
673
- }
674
- }, {
675
- key: "_initListeners",
676
- value: function _initListeners() {
677
- this._initTelInputListeners();
678
- if (this.options.allowDropdown) {
679
- this._initDropdownListeners();
680
- }
681
- if ((this.hiddenInput || this.hiddenInputCountry) && this.telInput.form) {
682
- this._initHiddenInputListener();
683
- }
684
- }
685
- }, {
686
- key: "_initHiddenInputListener",
687
- value: function _initHiddenInputListener() {
688
- var _this2 = this;
689
- this._handleHiddenInputSubmit = function() {
690
- if (_this2.hiddenInput) {
691
- _this2.hiddenInput.value = _this2.getNumber();
692
- }
693
- if (_this2.hiddenInputCountry) {
694
- _this2.hiddenInputCountry.value = _this2.getSelectedCountryData().iso2;
695
- }
696
- };
697
- this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit);
698
- }
699
- }, {
700
- key: "_initDropdownListeners",
701
- value: function _initDropdownListeners() {
702
- var _this3 = this;
703
- // hack for input nested inside label (which is valid markup): clicking the selected-flag to
704
- // open the dropdown would then automatically trigger a 2nd click on the input which would
705
- // close it again
706
- this._handleLabelClick = function(e) {
707
- // if the dropdown is closed, then focus the input, else ignore the click
708
- if (_this3.dropdownContent.classList.contains("iti__hide")) {
709
- _this3.telInput.focus();
710
- } else {
711
- e.preventDefault();
712
- }
713
- };
714
- var label = this.telInput.closest("label");
715
- if (label) {
716
- label.addEventListener("click", this._handleLabelClick);
717
- }
718
- // toggle country dropdown on click
719
- this._handleClickSelectedFlag = function() {
720
- // only intercept this event if we're opening the dropdown
721
- // else let it bubble up to the top ("click-off-to-close" listener)
722
- // we cannot just stopPropagation as it may be needed to close another instance
723
- if (_this3.dropdownContent.classList.contains("iti__hide") && !_this3.telInput.disabled && !_this3.telInput.readOnly) {
724
- _this3._openDropdown();
725
- }
726
- };
727
- this.selectedFlag.addEventListener("click", this._handleClickSelectedFlag);
728
- // open dropdown if selected flag is focused and they press up/down/space/enter
729
- this._handleFlagsContainerKeydown = function(e) {
730
- var isDropdownHidden = _this3.dropdownContent.classList.contains("iti__hide");
731
- if (isDropdownHidden && [ "ArrowUp", "ArrowDown", " ", "Enter" ].includes(e.key)) {
732
- // prevent form from being submitted if "ENTER" was pressed
733
- e.preventDefault();
734
- // prevent event from being handled again by document
735
- e.stopPropagation();
736
- _this3._openDropdown();
737
- }
738
- // allow navigation from dropdown to input on TAB
739
- if (e.key === "Tab") {
740
- _this3._closeDropdown();
741
- }
742
- };
743
- this.flagsContainer.addEventListener("keydown", this._handleFlagsContainerKeydown);
744
- }
745
- }, {
746
- key: "_initRequests",
747
- value: function _initRequests() {
748
- var _this4 = this;
749
- // if the user has specified the path to the utils script, fetch it on window.load, else resolve
750
- if (this.options.utilsScript && !window.intlTelInputUtils) {
751
- // if the plugin is being initialised after the window.load event has already been fired
752
- if (window.intlTelInputGlobals.documentReady()) {
753
- window.intlTelInputGlobals.loadUtils(this.options.utilsScript);
754
- } else {
755
- // wait until the load event so we don't block any other requests e.g. the flags image
756
- window.addEventListener("load", function() {
757
- window.intlTelInputGlobals.loadUtils(_this4.options.utilsScript);
758
- });
759
- }
760
- } else {
761
- this.resolveUtilsScriptPromise();
762
- }
763
- // dont bother with IP lookup if we already have a selected country
764
- if (this.options.initialCountry === "auto" && !this.selectedCountryData.iso2) {
765
- this._loadAutoCountry();
766
- } else {
767
- this.resolveAutoCountryPromise();
768
- }
769
- }
770
- }, {
771
- key: "_loadAutoCountry",
772
- value: function _loadAutoCountry() {
773
- var _this5 = this;
774
- // 3 options:
775
- // 1) already loaded (we're done)
776
- // 2) not already started loading (start)
777
- // 3) already started loading (do nothing - just wait for loading callback to fire)
778
- if (window.intlTelInputGlobals.autoCountry) {
779
- this.handleAutoCountry();
780
- } else if (!window.intlTelInputGlobals.startedLoadingAutoCountry) {
781
- // don't do this twice!
782
- window.intlTelInputGlobals.startedLoadingAutoCountry = true;
783
- if (typeof this.options.geoIpLookup === "function") {
784
- this.options.geoIpLookup(function() {
785
- var iso2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
786
- var iso2Lower = iso2.toLowerCase();
787
- var isValidIso2 = iso2Lower && _this5._getCountryData(iso2Lower, true);
788
- if (isValidIso2) {
789
- window.intlTelInputGlobals.autoCountry = iso2Lower;
790
- // tell all instances the auto country is ready
791
- // TODO: this should just be the current instances
792
- // UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight
793
- // away (e.g. if they have already done the geo ip lookup somewhere else). Using
794
- // setTimeout means that the current thread of execution will finish before executing
795
- // this, which allows the plugin to finish initialising.
796
- setTimeout(function() {
797
- return forEachInstance("handleAutoCountry");
798
- });
799
- } else {
800
- _this5._setInitialState(true);
801
- forEachInstance("rejectAutoCountryPromise");
802
- }
803
- }, function() {
804
- return forEachInstance("rejectAutoCountryPromise");
805
- });
806
- }
807
- }
808
- }
809
- }, {
810
- key: "_initTelInputListeners",
811
- value: function _initTelInputListeners() {
812
- var _this6 = this;
813
- var _this$options2 = this.options, strictMode = _this$options2.strictMode, formatAsYouType = _this$options2.formatAsYouType;
814
- var userOverrideFormatting = false;
815
- // update flag on input event
816
- this._handleInputEvent = function(e) {
817
- if (_this6._updateFlagFromNumber(_this6.telInput.value)) {
818
- _this6._triggerCountryChange();
819
- }
820
- // if user types their own formatting char (not a plus or a numeric), or they paste something, then set the override
821
- var isFormattingChar = e && e.data && /[^+0-9]/.test(e.data);
822
- var isPaste = e && e.inputType === "insertFromPaste" && _this6.telInput.value;
823
- if (isFormattingChar || isPaste && !strictMode) {
824
- userOverrideFormatting = true;
825
- } else if (!/[^+0-9]/.test(_this6.telInput.value)) {
826
- userOverrideFormatting = false;
827
- }
828
- // handle FAYT, unless userOverrideFormatting
829
- if (formatAsYouType && !userOverrideFormatting) {
830
- // maintain caret position after reformatting
831
- var currentCaretPos = _this6.telInput.selectionStart;
832
- var valueBeforeCaret = _this6.telInput.value.substring(0, currentCaretPos);
833
- var relevantCharsBeforeCaret = valueBeforeCaret.replace(/[^+0-9]/g, "").length;
834
- var isDeleteForwards = e && e.inputType === "deleteContentForward";
835
- var formattedValue = _this6._formatNumberAsYouType();
836
- var newCaretPos = _this6._translateCursorPosition(relevantCharsBeforeCaret, formattedValue, currentCaretPos, isDeleteForwards);
837
- _this6.telInput.value = formattedValue;
838
- _this6.telInput.setSelectionRange(newCaretPos, newCaretPos);
839
- }
840
- };
841
- // this handles individual key presses as well as cut/paste events
842
- // the advantage of the "input" event over "keyup" etc is that "input" only fires when the value changes,
843
- // whereas "keyup" fires even for shift key, arrow key presses etc
844
- this.telInput.addEventListener("input", this._handleInputEvent);
845
- if (strictMode) {
846
- this._handleKeydownEvent = function(e) {
847
- // only ignore actual character presses, rather than ctrl, alt, shift, command, arrow keys, delete/backspace, cut/copy/paste etc
848
- if (e.key.length === 1 && !e.altKey && !e.ctrlKey && !e.metaKey) {
849
- var isInitialPlus = _this6.telInput.selectionStart === 0 && e.key === "+";
850
- var isNumeric = /^[0-9]$/.test(e.key);
851
- var isAllowedChar = isInitialPlus || isNumeric;
852
- var fullNumber = _this6._getFullNumber();
853
- var coreNumber = intlTelInputUtils.getCoreNumber(fullNumber, _this6.selectedCountryData.iso2);
854
- var hasReachedMaxLength = _this6.maxCoreNumberLength && coreNumber.length >= _this6.maxCoreNumberLength;
855
- if (!isAllowedChar || hasReachedMaxLength) {
856
- e.preventDefault();
857
- }
858
- }
859
- };
860
- this.telInput.addEventListener("keydown", this._handleKeydownEvent);
861
- }
862
- }
863
- }, {
864
- key: "_translateCursorPosition",
865
- value: function _translateCursorPosition(relevantChars, formattedValue, prevCaretPos, isDeleteForwards) {
866
- // if the first char is a formatting char, and they backspace delete it:
867
- // cursor should stay at the start (pos 0), rather than stick to the first digit (pos 1)
868
- if (prevCaretPos === 0 && !isDeleteForwards) {
869
- return 0;
870
- }
871
- var count = 0;
872
- for (var i = 0; i < formattedValue.length; i++) {
873
- if (/[+0-9]/.test(formattedValue[i])) {
874
- count++;
875
- }
876
- // normal case: stop when you hit the right number of relevant chars
877
- // (cursor will be just after the final relevant char)
878
- if (count === relevantChars && !isDeleteForwards) {
879
- return i + 1;
880
- }
881
- // spacial case: delete forwards (fn + delete on a mac):
882
- // wait until hit one extra relevant char, and put the cursor just before it (after any formatting chars)
883
- if (isDeleteForwards && count === relevantChars + 1) {
884
- return i;
885
- }
886
- }
887
- return formattedValue.length;
888
- }
889
- }, {
890
- key: "_cap",
891
- value: function _cap(number) {
892
- var max = this.telInput.getAttribute("maxlength");
893
- return max && number.length > max ? number.substr(0, max) : number;
894
- }
895
- }, {
896
- key: "_removeEmptyDialCode",
897
- value: function _removeEmptyDialCode() {
898
- if (this.telInput.value.charAt(0) === "+") {
899
- var numeric = this._getNumeric(this.telInput.value);
900
- // if just a plus, or if just a dial code
901
- if (!numeric || this.selectedCountryData.dialCode === numeric) {
902
- this.telInput.value = "";
903
- }
904
- }
905
- }
906
- }, {
907
- key: "_getNumeric",
908
- value: function _getNumeric(s) {
909
- return s.replace(/\D/g, "");
910
- }
911
- }, {
912
- key: "_trigger",
913
- value: function _trigger(name) {
914
- var e = new Event(name, {
915
- bubbles: true,
916
- cancelable: true
917
- });
918
- this.telInput.dispatchEvent(e);
919
- }
920
- }, {
921
- key: "_openDropdown",
922
- value: function _openDropdown() {
923
- var _this$options3 = this.options, fixDropdownWidth = _this$options3.fixDropdownWidth, countrySearch = _this$options3.countrySearch;
924
- if (fixDropdownWidth) {
925
- this.dropdownContent.style.width = "".concat(this.telInput.offsetWidth, "px");
926
- }
927
- this.dropdownContent.classList.remove("iti__hide");
928
- this.selectedFlag.setAttribute("aria-expanded", "true");
929
- this._setDropdownPosition();
930
- // if we have previously selected a country (and countrySearch is disabled), then highlight that item and scroll to it
931
- // else highlight the first item and scroll to top (even if countrySearch is disabled e.g. on init, showing globe icon)
932
- if (this.activeItem && !countrySearch) {
933
- // update highlighting and scroll to active list item
934
- this._highlightListItem(this.activeItem, false);
935
- this._scrollTo(this.activeItem, true);
936
- } else {
937
- // start by highlighting the first item in the list
938
- var firstElementChild = this.countryList.firstElementChild;
939
- if (firstElementChild) {
940
- this._highlightListItem(firstElementChild, false);
941
- this.countryList.scrollTop = 0;
942
- }
943
- if (countrySearch) {
944
- this.searchInput.focus();
945
- }
946
- }
947
- // bind all the dropdown-related listeners: mouseover, click, click-off, keydown
948
- this._bindDropdownListeners();
949
- // update the arrow
950
- this.dropdownArrow.classList.add("iti__arrow--up");
951
- this._trigger("open:countrydropdown");
952
- }
953
- }, {
954
- key: "_toggleClass",
955
- value: function _toggleClass(el, className, shouldHaveClass) {
956
- if (shouldHaveClass && !el.classList.contains(className)) {
957
- el.classList.add(className);
958
- } else if (!shouldHaveClass && el.classList.contains(className)) {
959
- el.classList.remove(className);
960
- }
961
- }
962
- }, {
963
- key: "_setDropdownPosition",
964
- value: function _setDropdownPosition() {
965
- var _this7 = this;
966
- if (this.options.dropdownContainer) {
967
- this.options.dropdownContainer.appendChild(this.dropdown);
968
- }
969
- if (!this.options.useFullscreenPopup) {
970
- var pos = this.telInput.getBoundingClientRect();
971
- // windowTop from https://stackoverflow.com/a/14384091/217866
972
- var windowTop = document.documentElement.scrollTop;
973
- var inputTop = pos.top + windowTop;
974
- var dropdownHeight = this.dropdownContent.offsetHeight;
975
- // dropdownFitsBelow = (dropdownBottom < windowBottom)
976
- var dropdownFitsBelow = inputTop + this.telInput.offsetHeight + dropdownHeight < windowTop + window.innerHeight;
977
- var dropdownFitsAbove = inputTop - dropdownHeight > windowTop;
978
- // dont allow positioning above when country search enabled as the search box jumps around as you filter countries
979
- var positionDropdownAboveInput = !this.options.countrySearch && !dropdownFitsBelow && dropdownFitsAbove;
980
- // by default, the dropdown will be below the input. If we want to position it above the
981
- // input, we add the dropup class.
982
- this._toggleClass(this.dropdownContent, "iti__dropdown-content--dropup", positionDropdownAboveInput);
983
- // if dropdownContainer is enabled, calculate postion
984
- if (this.options.dropdownContainer) {
985
- // if we want to position the dropdown below the input, we need to add the input height to the top value
986
- var extraTop = positionDropdownAboveInput ? 0 : this.telInput.offsetHeight;
987
- // calculate placement
988
- this.dropdown.style.top = "".concat(inputTop + extraTop, "px");
989
- this.dropdown.style.left = "".concat(pos.left + document.body.scrollLeft, "px");
990
- // close menu on window scroll
991
- this._handleWindowScroll = function() {
992
- return _this7._closeDropdown();
993
- };
994
- window.addEventListener("scroll", this._handleWindowScroll);
995
- }
996
- }
997
- }
998
- }, {
999
- key: "_bindDropdownListeners",
1000
- value: function _bindDropdownListeners() {
1001
- var _this8 = this;
1002
- // when mouse over a list item, just highlight that one
1003
- // we add the class "highlight", so if they hit "enter" we know which one to select
1004
- this._handleMouseoverCountryList = function(e) {
1005
- // handle event delegation, as we're listening for this event on the countryList
1006
- var listItem = e.target.closest(".iti__country");
1007
- if (listItem) {
1008
- _this8._highlightListItem(listItem, false);
1009
- }
1010
- };
1011
- this.countryList.addEventListener("mouseover", this._handleMouseoverCountryList);
1012
- // listen for country selection
1013
- this._handleClickCountryList = function(e) {
1014
- var listItem = e.target.closest(".iti__country");
1015
- if (listItem) {
1016
- _this8._selectListItem(listItem);
1017
- }
1018
- };
1019
- this.countryList.addEventListener("click", this._handleClickCountryList);
1020
- // click off to close
1021
- // (except when this initial opening click is bubbling up)
1022
- // we cannot just stopPropagation as it may be needed to close another instance
1023
- var isOpening = true;
1024
- this._handleClickOffToClose = function() {
1025
- if (!isOpening) {
1026
- _this8._closeDropdown();
1027
- }
1028
- isOpening = false;
1029
- };
1030
- document.documentElement.addEventListener("click", this._handleClickOffToClose);
1031
- // listen for up/down scrolling, enter to select, or escape to close
1032
- // use keydown as keypress doesn't fire for non-char keys and we want to catch if they
1033
- // just hit down and hold it to scroll down (no keyup event).
1034
- // listen on the document because that's where key events are triggered if no input has focus
1035
- var query = "";
1036
- var queryTimer = null;
1037
- this._handleKeydownOnDropdown = function(e) {
1038
- // prevent down key from scrolling the whole page,
1039
- // and enter key from submitting a form etc
1040
- if ([ "ArrowUp", "ArrowDown", "Enter", "Escape" ].includes(e.key)) {
1041
- e.preventDefault();
1042
- e.stopPropagation();
1043
- // up and down to navigate
1044
- if (e.key === "ArrowUp" || e.key === "ArrowDown") {
1045
- _this8._handleUpDownKey(e.key);
1046
- } else if (e.key === "Enter") {
1047
- _this8._handleEnterKey();
1048
- } else if (e.key === "Escape") {
1049
- _this8._closeDropdown();
1050
- }
1051
- }
1052
- // alpha chars to perform search
1053
- // regex allows one latin alpha char or space, based on https://stackoverflow.com/a/26900132/217866)
1054
- if (!_this8.options.countrySearch && /^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(e.key)) {
1055
- e.stopPropagation();
1056
- // jump to countries that start with the query string
1057
- if (queryTimer) {
1058
- clearTimeout(queryTimer);
1059
- }
1060
- query += e.key.toLowerCase();
1061
- _this8._searchForCountry(query);
1062
- // if the timer hits 1 second, reset the query
1063
- queryTimer = setTimeout(function() {
1064
- query = "";
1065
- }, 1e3);
1066
- }
1067
- };
1068
- document.addEventListener("keydown", this._handleKeydownOnDropdown);
1069
- if (this.options.countrySearch) {
1070
- var doFilter = function doFilter() {
1071
- var inputQuery = _this8.searchInput.value.trim();
1072
- if (inputQuery) {
1073
- _this8._filterCountries(inputQuery);
1074
- } else {
1075
- _this8._filterCountries("", true);
1076
- }
1077
- };
1078
- var keyupTimer = null;
1079
- this._handleSearchChange = function() {
1080
- // filtering country nodes is expensive (lots of DOM manipulation), so rate limit it
1081
- if (keyupTimer) {
1082
- clearTimeout(keyupTimer);
1083
- }
1084
- keyupTimer = setTimeout(function() {
1085
- doFilter();
1086
- keyupTimer = null;
1087
- }, 100);
1088
- };
1089
- this.searchInput.addEventListener("input", this._handleSearchChange);
1090
- // stop propagation on search input click, so doesn't trigger click-off-to-close listener
1091
- this.searchInput.addEventListener("click", function(e) {
1092
- return e.stopPropagation();
1093
- });
1094
- }
1095
- }
1096
- }, {
1097
- key: "_normaliseString",
1098
- value: function _normaliseString() {
1099
- var s = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
1100
- return s.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
1101
- }
1102
- }, {
1103
- key: "_filterCountries",
1104
- value: function _filterCountries(query) {
1105
- var isReset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1106
- var isFirst = true;
1107
- this.countryList.innerHTML = "";
1108
- var normalisedQuery = this._normaliseString(query);
1109
- for (var i = 0; i < this.countries.length; i++) {
1110
- var c = this.countries[i];
1111
- var normalisedCountryName = this._normaliseString(c.name);
1112
- var fullDialCode = "+".concat(c.dialCode);
1113
- if (isReset || normalisedCountryName.includes(normalisedQuery) || fullDialCode.includes(normalisedQuery) || c.iso2.includes(normalisedQuery)) {
1114
- this.countryList.appendChild(c.nodeById[this.id]);
1115
- // highlight the first item
1116
- if (isFirst) {
1117
- this._highlightListItem(c.nodeById[this.id], false);
1118
- isFirst = false;
1119
- }
1120
- }
1121
- }
1122
- // scroll to top (useful if user had previously scrolled down)
1123
- this.countryList.scrollTop = 0;
1124
- this._updateSearchResultsText();
1125
- }
1126
- }, {
1127
- key: "_updateSearchResultsText",
1128
- value: function _updateSearchResultsText() {
1129
- var i18n = this.options.i18n;
1130
- var count = this.countryList.childElementCount;
1131
- var searchText;
1132
- if (count === 0) {
1133
- searchText = i18n.zeroSearchResults || "No results found";
1134
- } else if (count === 1) {
1135
- searchText = i18n.oneSearchResult || "1 result found";
1136
- } else {
1137
- // eslint-disable-next-line no-template-curly-in-string
1138
- searchText = i18n.multipleSearchResults ? i18n.multipleSearchResults.replace("${count}", count) : "".concat(count, " results found");
1139
- }
1140
- this.searchResultsA11yText.textContent = searchText;
1141
- }
1142
- }, {
1143
- key: "_handleUpDownKey",
1144
- value: function _handleUpDownKey(key) {
1145
- var next = key === "ArrowUp" ? this.highlightedItem.previousElementSibling : this.highlightedItem.nextElementSibling;
1146
- if (next) {
1147
- // skip the divider
1148
- if (next.classList.contains("iti__divider")) {
1149
- next = key === "ArrowUp" ? next.previousElementSibling : next.nextElementSibling;
1150
- }
1151
- } else if (this.countryList.childElementCount > 1) {
1152
- // otherwise, we must be at the end, so loop round again
1153
- next = key === "ArrowUp" ? this.countryList.lastElementChild : this.countryList.firstElementChild;
1154
- }
1155
- if (next) {
1156
- // make sure the next item is visible
1157
- // (before calling focus(), which can cause the next item to scroll to the middle of the dropdown, which is jarring)
1158
- this._scrollTo(next, false);
1159
- // if country search enabled, dont lose focus from the search input on up/down
1160
- var doFocus = !this.options.countrySearch;
1161
- this._highlightListItem(next, doFocus);
1162
- }
1163
- }
1164
- }, {
1165
- key: "_handleEnterKey",
1166
- value: function _handleEnterKey() {
1167
- if (this.highlightedItem) {
1168
- this._selectListItem(this.highlightedItem);
1169
- }
1170
- }
1171
- }, {
1172
- key: "_searchForCountry",
1173
- value: function _searchForCountry(query) {
1174
- for (var i = 0; i < this.countries.length; i++) {
1175
- if (this._startsWith(this.countries[i].name, query)) {
1176
- var listItem = this.countries[i].nodeById[this.id];
1177
- // update highlighting and scroll
1178
- this._highlightListItem(listItem, false);
1179
- this._scrollTo(listItem, true);
1180
- break;
1181
- }
1182
- }
1183
- }
1184
- }, {
1185
- key: "_startsWith",
1186
- value: function _startsWith(a, b) {
1187
- return a.substr(0, b.length).toLowerCase() === b;
1188
- }
1189
- }, {
1190
- key: "_updateValFromNumber",
1191
- value: function _updateValFromNumber(fullNumber) {
1192
- var number = fullNumber;
1193
- if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) {
1194
- var useNational = this.options.nationalMode || number.charAt(0) !== "+" && !this.options.showSelectedDialCode;
1195
- var _intlTelInputUtils$nu = intlTelInputUtils.numberFormat, NATIONAL = _intlTelInputUtils$nu.NATIONAL, INTERNATIONAL = _intlTelInputUtils$nu.INTERNATIONAL;
1196
- var format = useNational ? NATIONAL : INTERNATIONAL;
1197
- number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format);
1198
- }
1199
- number = this._beforeSetNumber(number);
1200
- this.telInput.value = number;
1201
- }
1202
- }, {
1203
- key: "_updateFlagFromNumber",
1204
- value: function _updateFlagFromNumber(fullNumber) {
1205
- var plusIndex = fullNumber.indexOf("+");
1206
- // if it contains a plus, discard any chars before it e.g. accidental space char.
1207
- // this keeps the selected country auto-updating correctly, which we want as
1208
- // libphonenumber's validation/getNumber methods will ignore these chars anyway
1209
- var number = plusIndex ? fullNumber.substring(plusIndex) : fullNumber;
1210
- // if we already have US/Canada selected, make sure the number starts
1211
- // with a +1 so _getDialCode will be able to extract the area code
1212
- // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag
1213
- // from the number), that means we're initialising the plugin with a number that already has a
1214
- // dial code, so fine to ignore this bit
1215
- var selectedDialCode = this.selectedCountryData.dialCode;
1216
- var isNanp = selectedDialCode === "1";
1217
- if (number && isNanp && number.charAt(0) !== "+") {
1218
- if (number.charAt(0) !== "1") {
1219
- number = "1".concat(number);
1220
- }
1221
- number = "+".concat(number);
1222
- }
1223
- // if showSelectedDialCode enabled, then consider the selected dial code to be part of the number
1224
- if (this.options.showSelectedDialCode && selectedDialCode && number.charAt(0) !== "+") {
1225
- number = "+".concat(selectedDialCode).concat(number);
1226
- }
1227
- // try and extract valid dial code from input
1228
- var dialCode = this._getDialCode(number, true);
1229
- var numeric = this._getNumeric(number);
1230
- var iso2 = null;
1231
- if (dialCode) {
1232
- var iso2Codes = this.dialCodeToIso2Map[this._getNumeric(dialCode)];
1233
- // check if the right country is already selected. this should be false if the number is
1234
- // longer than the matched dial code because in this case we need to make sure that if
1235
- // there are multiple country matches, that the first one is selected (note: we could
1236
- // just check that here, but it requires the same loop that we already have later)
1237
- var alreadySelected = iso2Codes.indexOf(this.selectedCountryData.iso2) !== -1 && numeric.length <= dialCode.length - 1;
1238
- var isRegionlessNanpNumber = selectedDialCode === "1" && this._isRegionlessNanp(numeric);
1239
- // only update the flag if:
1240
- // A) NOT (we currently have a NANP flag selected, and the number is a regionlessNanp)
1241
- // AND
1242
- // B) the right country is not already selected
1243
- if (!isRegionlessNanpNumber && !alreadySelected) {
1244
- // if using onlyCountries option, iso2Codes[0] may be empty, so we must find the first
1245
- // non-empty index
1246
- for (var j = 0; j < iso2Codes.length; j++) {
1247
- if (iso2Codes[j]) {
1248
- iso2 = iso2Codes[j];
1249
- break;
1250
- }
1251
- }
1252
- }
1253
- } else if (number.charAt(0) === "+" && numeric.length) {
1254
- // invalid dial code, so empty
1255
- // Note: use getNumeric here because the number has not been formatted yet, so could contain
1256
- // bad chars
1257
- iso2 = "";
1258
- } else if ((!number || number === "+") && !this.selectedCountryData.iso2) {
1259
- // if no selected flag, and user either clears the input, or just types a plus, then show default
1260
- iso2 = this.defaultCountry;
1261
- }
1262
- if (iso2 !== null) {
1263
- return this._setCountry(iso2);
1264
- }
1265
- return false;
1266
- }
1267
- }, {
1268
- key: "_isRegionlessNanp",
1269
- value: function _isRegionlessNanp(number) {
1270
- var numeric = this._getNumeric(number);
1271
- if (numeric.charAt(0) === "1") {
1272
- var areaCode = numeric.substr(1, 3);
1273
- return regionlessNanpNumbers.indexOf(areaCode) !== -1;
1274
- }
1275
- return false;
1276
- }
1277
- }, {
1278
- key: "_highlightListItem",
1279
- value: function _highlightListItem(listItem, shouldFocus) {
1280
- var prevItem = this.highlightedItem;
1281
- if (prevItem) {
1282
- prevItem.classList.remove("iti__highlight");
1283
- prevItem.setAttribute("aria-selected", "false");
1284
- }
1285
- this.highlightedItem = listItem;
1286
- this.highlightedItem.classList.add("iti__highlight");
1287
- this.highlightedItem.setAttribute("aria-selected", "true");
1288
- this.selectedFlag.setAttribute("aria-activedescendant", listItem.getAttribute("id"));
1289
- if (this.options.countrySearch) {
1290
- this.searchInput.setAttribute("aria-activedescendant", listItem.getAttribute("id"));
1291
- }
1292
- if (shouldFocus) {
1293
- this.highlightedItem.focus();
1294
- }
1295
- }
1296
- }, {
1297
- key: "_getCountryData",
1298
- value: function _getCountryData(iso2, allowFail) {
1299
- for (var i = 0; i < this.countries.length; i++) {
1300
- if (this.countries[i].iso2 === iso2) {
1301
- return this.countries[i];
1302
- }
1303
- }
1304
- if (allowFail) {
1305
- return null;
1306
- }
1307
- throw new Error("No country data for '".concat(iso2, "'"));
1308
- }
1309
- }, {
1310
- key: "_setCountry",
1311
- value: function _setCountry(iso2) {
1312
- 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;
1313
- var prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {};
1314
- // do this first as it will throw an error and stop if iso2 is invalid
1315
- this.selectedCountryData = iso2 ? this._getCountryData(iso2, false) : {};
1316
- // update the defaultCountry - we only need the iso2 from now on, so just store that
1317
- if (this.selectedCountryData.iso2) {
1318
- this.defaultCountry = this.selectedCountryData.iso2;
1319
- }
1320
- // update the flag class and the a11y text
1321
- if (this.selectedFlagInner) {
1322
- var flagClass = "";
1323
- var a11yText = "";
1324
- if (iso2) {
1325
- if (showFlags) {
1326
- flagClass = "iti__flag iti__".concat(iso2);
1327
- a11yText = "".concat(this.selectedCountryData.name, " +").concat(this.selectedCountryData.dialCode);
1328
- }
1329
- } else {
1330
- flagClass = "iti__flag iti__globe";
1331
- a11yText = i18n.noCountrySelected || "No country selected";
1332
- }
1333
- this.selectedFlagInner.className = flagClass;
1334
- this.selectedFlagA11yText.textContent = a11yText;
1335
- }
1336
- this._setSelectedCountryFlagTitleAttribute(iso2, showSelectedDialCode);
1337
- // update the selected dial code
1338
- if (showSelectedDialCode) {
1339
- var dialCode = this.selectedCountryData.dialCode ? "+".concat(this.selectedCountryData.dialCode) : "";
1340
- this.selectedDialCode.innerHTML = dialCode;
1341
- // offsetWidth is zero if input is in a hidden container during initialisation
1342
- var selectedFlagWidth = this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth();
1343
- // add 6px of padding after the grey selected-dial-code box, as this is what we use in the css
1344
- if (this.isRTL) {
1345
- this.telInput.style.paddingRight = "".concat(selectedFlagWidth + 6, "px");
1346
- } else {
1347
- this.telInput.style.paddingLeft = "".concat(selectedFlagWidth + 6, "px");
1348
- }
1349
- }
1350
- // and the input's placeholder
1351
- this._updatePlaceholder();
1352
- // update the maximum valid number length
1353
- this._updateMaxLength();
1354
- // update the active list item (only if country search disabled, as country search doesn't store the active item)
1355
- if (allowDropdown && !countrySearch) {
1356
- var prevItem = this.activeItem;
1357
- if (prevItem) {
1358
- prevItem.classList.remove("iti__active");
1359
- prevItem.setAttribute("aria-selected", "false");
1360
- }
1361
- if (iso2) {
1362
- // check if there is a preferred item first, else fall back to standard
1363
- var nextItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(iso2, "-preferred")) || this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(iso2));
1364
- nextItem.setAttribute("aria-selected", "true");
1365
- nextItem.classList.add("iti__active");
1366
- this.activeItem = nextItem;
1367
- }
1368
- }
1369
- // return if the flag has changed or not
1370
- return prevCountry.iso2 !== iso2;
1371
- }
1372
- }, {
1373
- key: "_updateMaxLength",
1374
- value: function _updateMaxLength() {
1375
- if (this.options.strictMode && window.intlTelInputUtils) {
1376
- if (this.selectedCountryData.iso2) {
1377
- var numberType = intlTelInputUtils.numberType[this.options.placeholderNumberType];
1378
- var exampleNumber = intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, null, numberType, true);
1379
- // see if adding more digits is still valid to get the true maximum valid length
1380
- var validNumber = exampleNumber;
1381
- while (intlTelInputUtils.isPossibleNumber(exampleNumber, this.selectedCountryData.iso2)) {
1382
- validNumber = exampleNumber;
1383
- exampleNumber += "0";
1384
- }
1385
- var coreNumber = intlTelInputUtils.getCoreNumber(validNumber, this.selectedCountryData.iso2);
1386
- this.maxCoreNumberLength = coreNumber.length;
1387
- } else {
1388
- this.maxCoreNumberLength = null;
1389
- }
1390
- }
1391
- }
1392
- }, {
1393
- key: "_setSelectedCountryFlagTitleAttribute",
1394
- value: function _setSelectedCountryFlagTitleAttribute(iso2, showSelectedDialCode) {
1395
- if (!this.selectedFlag) {
1396
- return;
1397
- }
1398
- var title;
1399
- if (iso2 && !showSelectedDialCode) {
1400
- title = "".concat(this.selectedCountryData.name, ": +").concat(this.selectedCountryData.dialCode);
1401
- } else if (iso2) {
1402
- // For screen reader output, we don't want to include the dial code in the reader output twice
1403
- // so just use the selected country name here:
1404
- title = this.selectedCountryData.name;
1405
- } else {
1406
- title = "Unknown";
1407
- }
1408
- this.selectedFlag.setAttribute("title", title);
1409
- }
1410
- }, {
1411
- key: "_getHiddenSelectedFlagWidth",
1412
- value: function _getHiddenSelectedFlagWidth() {
1413
- // to get the right styling to apply, all we need is a shallow clone of the container,
1414
- // and then to inject a deep clone of the selectedFlag element
1415
- var containerClone = this.telInput.parentNode.cloneNode();
1416
- containerClone.style.visibility = "hidden";
1417
- document.body.appendChild(containerClone);
1418
- var flagsContainerClone = this.flagsContainer.cloneNode();
1419
- containerClone.appendChild(flagsContainerClone);
1420
- var selectedFlagClone = this.selectedFlag.cloneNode(true);
1421
- flagsContainerClone.appendChild(selectedFlagClone);
1422
- var width = selectedFlagClone.offsetWidth;
1423
- containerClone.parentNode.removeChild(containerClone);
1424
- return width;
1425
- }
1426
- }, {
1427
- key: "_updatePlaceholder",
1428
- value: function _updatePlaceholder() {
1429
- var _this$options5 = this.options, autoPlaceholder = _this$options5.autoPlaceholder, placeholderNumberType = _this$options5.placeholderNumberType, nationalMode = _this$options5.nationalMode, customPlaceholder = _this$options5.customPlaceholder;
1430
- var shouldSetPlaceholder = autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && autoPlaceholder === "polite";
1431
- if (window.intlTelInputUtils && shouldSetPlaceholder) {
1432
- var numberType = intlTelInputUtils.numberType[placeholderNumberType];
1433
- // note: must set placeholder to empty string if no country selected (globe icon showing)
1434
- var placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, nationalMode, numberType) : "";
1435
- placeholder = this._beforeSetNumber(placeholder);
1436
- if (typeof customPlaceholder === "function") {
1437
- placeholder = customPlaceholder(placeholder, this.selectedCountryData);
1438
- }
1439
- this.telInput.setAttribute("placeholder", placeholder);
1440
- }
1441
- }
1442
- }, {
1443
- key: "_selectListItem",
1444
- value: function _selectListItem(listItem) {
1445
- // update selected flag and active list item
1446
- var flagChanged = this._setCountry(listItem.getAttribute("data-country-code"));
1447
- this._closeDropdown();
1448
- this._updateDialCode(listItem.getAttribute("data-dial-code"));
1449
- // focus the input
1450
- this.telInput.focus();
1451
- if (flagChanged) {
1452
- this._triggerCountryChange();
1453
- }
1454
- }
1455
- }, {
1456
- key: "_closeDropdown",
1457
- value: function _closeDropdown() {
1458
- this.dropdownContent.classList.add("iti__hide");
1459
- this.selectedFlag.setAttribute("aria-expanded", "false");
1460
- this.selectedFlag.removeAttribute("aria-activedescendant");
1461
- if (this.highlightedItem) {
1462
- this.highlightedItem.setAttribute("aria-selected", "false");
1463
- }
1464
- if (this.options.countrySearch) {
1465
- this.searchInput.removeAttribute("aria-activedescendant");
1466
- }
1467
- // update the arrow
1468
- this.dropdownArrow.classList.remove("iti__arrow--up");
1469
- // unbind key events
1470
- document.removeEventListener("keydown", this._handleKeydownOnDropdown);
1471
- if (this.options.countrySearch) {
1472
- this.searchInput.removeEventListener("input", this._handleSearchChange);
1473
- }
1474
- document.documentElement.removeEventListener("click", this._handleClickOffToClose);
1475
- this.countryList.removeEventListener("mouseover", this._handleMouseoverCountryList);
1476
- this.countryList.removeEventListener("click", this._handleClickCountryList);
1477
- // remove menu from container
1478
- if (this.options.dropdownContainer) {
1479
- if (!this.options.useFullscreenPopup) {
1480
- window.removeEventListener("scroll", this._handleWindowScroll);
1481
- }
1482
- if (this.dropdown.parentNode) {
1483
- this.dropdown.parentNode.removeChild(this.dropdown);
1484
- }
1485
- }
1486
- this._trigger("close:countrydropdown");
1487
- }
1488
- }, {
1489
- key: "_scrollTo",
1490
- value: function _scrollTo(element, middle) {
1491
- var container = this.countryList;
1492
- // windowTop from https://stackoverflow.com/a/14384091/217866
1493
- var windowTop = document.documentElement.scrollTop;
1494
- var containerHeight = container.offsetHeight;
1495
- var containerTop = container.getBoundingClientRect().top + windowTop;
1496
- var containerBottom = containerTop + containerHeight;
1497
- var elementHeight = element.offsetHeight;
1498
- var elementTop = element.getBoundingClientRect().top + windowTop;
1499
- var elementBottom = elementTop + elementHeight;
1500
- var newScrollTop = elementTop - containerTop + container.scrollTop;
1501
- var middleOffset = containerHeight / 2 - elementHeight / 2;
1502
- if (elementTop < containerTop) {
1503
- // scroll up
1504
- if (middle) {
1505
- newScrollTop -= middleOffset;
1506
- }
1507
- container.scrollTop = newScrollTop;
1508
- } else if (elementBottom > containerBottom) {
1509
- // scroll down
1510
- if (middle) {
1511
- newScrollTop += middleOffset;
1512
- }
1513
- var heightDifference = containerHeight - elementHeight;
1514
- container.scrollTop = newScrollTop - heightDifference;
1515
- }
1516
- }
1517
- }, {
1518
- key: "_updateDialCode",
1519
- value: function _updateDialCode(newDialCodeBare) {
1520
- var inputVal = this.telInput.value;
1521
- // save having to pass this every time
1522
- var newDialCode = "+".concat(newDialCodeBare);
1523
- var newNumber;
1524
- if (inputVal.charAt(0) === "+") {
1525
- // there's a plus so we're dealing with a replacement
1526
- var prevDialCode = this._getDialCode(inputVal);
1527
- if (prevDialCode) {
1528
- // current number contains a valid dial code, so replace it
1529
- newNumber = inputVal.replace(prevDialCode, newDialCode);
1530
- } else {
1531
- // current number contains an invalid dial code, so ditch it
1532
- // (no way to determine where the invalid dial code ends and the rest of the number begins)
1533
- newNumber = newDialCode;
1534
- }
1535
- this.telInput.value = newNumber;
1536
- }
1537
- }
1538
- }, {
1539
- key: "_getDialCode",
1540
- value: function _getDialCode(number, includeAreaCode) {
1541
- var dialCode = "";
1542
- // only interested in international numbers (starting with a plus)
1543
- if (number.charAt(0) === "+") {
1544
- var numericChars = "";
1545
- // iterate over chars
1546
- for (var i = 0; i < number.length; i++) {
1547
- var c = number.charAt(i);
1548
- // if char is number (https://stackoverflow.com/a/8935649/217866)
1549
- if (!isNaN(parseInt(c, 10))) {
1550
- numericChars += c;
1551
- // if current numericChars make a valid dial code
1552
- if (includeAreaCode) {
1553
- if (this.dialCodeToIso2Map[numericChars]) {
1554
- // store the actual raw string (useful for matching later)
1555
- dialCode = number.substr(0, i + 1);
1556
- }
1557
- } else {
1558
- if (this.dialCodes[numericChars]) {
1559
- dialCode = number.substr(0, i + 1);
1560
- // if we're just looking for a dial code, we can break as soon as we find one
1561
- break;
1562
- }
1563
- }
1564
- // stop searching as soon as we can - in this case when we hit max len
1565
- if (numericChars.length === this.dialCodeMaxLen) {
1566
- break;
1567
- }
1568
- }
1569
- }
1570
- }
1571
- return dialCode;
1572
- }
1573
- }, {
1574
- key: "_getFullNumber",
1575
- value: function _getFullNumber() {
1576
- var val = this.telInput.value.trim();
1577
- var dialCode = this.selectedCountryData.dialCode;
1578
- var prefix;
1579
- var numericVal = this._getNumeric(val);
1580
- if (this.options.showSelectedDialCode && !this.options.nationalMode && val.charAt(0) !== "+" && dialCode && numericVal) {
1581
- // when using showSelectedDialCode, it is visible so is effectively part of the typed number
1582
- prefix = "+".concat(dialCode);
1583
- } else {
1584
- prefix = "";
1585
- }
1586
- return prefix + val;
1587
- }
1588
- }, {
1589
- key: "_beforeSetNumber",
1590
- value: function _beforeSetNumber(fullNumber) {
1591
- var number = fullNumber;
1592
- if (this.options.showSelectedDialCode) {
1593
- var dialCode = this._getDialCode(number);
1594
- // if there is a valid dial code
1595
- if (dialCode) {
1596
- // in case _getDialCode returned an area code as well
1597
- dialCode = "+".concat(this.selectedCountryData.dialCode);
1598
- // a lot of numbers will have a space separating the dial code and the main number, and
1599
- // some NANP numbers will have a hyphen e.g. +1 684-733-1234 - in both cases we want to get
1600
- // rid of it
1601
- // NOTE: don't just trim all non-numerics as may want to preserve an open parenthesis etc
1602
- var start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
1603
- number = number.substr(start);
1604
- }
1605
- }
1606
- return this._cap(number);
1607
- }
1608
- }, {
1609
- key: "_triggerCountryChange",
1610
- value: function _triggerCountryChange() {
1611
- this._trigger("countrychange");
1612
- }
1613
- }, {
1614
- key: "_formatNumberAsYouType",
1615
- value: function _formatNumberAsYouType() {
1616
- var val = this._getFullNumber();
1617
- var result = window.intlTelInputUtils ? intlTelInputUtils.formatNumberAsYouType(val, this.selectedCountryData.iso2) : val;
1618
- // if showSelectedDialCode and they haven't (re)typed the dial code in the input as well, then remove the dial code
1619
- var dialCode = this.selectedCountryData.dialCode;
1620
- if (this.options.showSelectedDialCode && !this.options.nationalMode && this.telInput.value.charAt(0) !== "+" && result.includes("+".concat(dialCode))) {
1621
- var afterDialCode = result.split("+".concat(dialCode))[1] || "";
1622
- return afterDialCode.trim();
1623
- }
1624
- return result;
1625
- }
1626
- }, {
1627
- key: "handleAutoCountry",
1628
- value: function handleAutoCountry() {
1629
- if (this.options.initialCountry === "auto") {
1630
- // we must set this even if there is an initial val in the input: in case the initial val is
1631
- // invalid and they delete it - they should see their auto country
1632
- this.defaultCountry = window.intlTelInputGlobals.autoCountry;
1633
- // if there's no initial value in the input, then update the flag
1634
- if (!this.telInput.value) {
1635
- this.setCountry(this.defaultCountry);
1636
- }
1637
- this.resolveAutoCountryPromise();
1638
- }
1639
- }
1640
- }, {
1641
- key: "handleUtils",
1642
- value: function handleUtils() {
1643
- // if the request was successful
1644
- if (window.intlTelInputUtils) {
1645
- // if there's an initial value in the input, then format it
1646
- if (this.telInput.value) {
1647
- this._updateValFromNumber(this.telInput.value);
1648
- }
1649
- if (this.selectedCountryData.iso2) {
1650
- this._updatePlaceholder();
1651
- this._updateMaxLength();
1652
- }
1653
- }
1654
- this.resolveUtilsScriptPromise();
1655
- }
1656
- }, {
1657
- key: "destroy",
1658
- value: function destroy() {
1659
- if (this.options.allowDropdown) {
1660
- // make sure the dropdown is closed (and unbind listeners)
1661
- this._closeDropdown();
1662
- this.selectedFlag.removeEventListener("click", this._handleClickSelectedFlag);
1663
- this.flagsContainer.removeEventListener("keydown", this._handleFlagsContainerKeydown);
1664
- // label click hack
1665
- var label = this.telInput.closest("label");
1666
- if (label) {
1667
- label.removeEventListener("click", this._handleLabelClick);
1668
- }
1669
- }
1670
- // unbind hiddenInput listeners
1671
- var form = this.telInput.form;
1672
- if (this._handleHiddenInputSubmit && form) {
1673
- form.removeEventListener("submit", this._handleHiddenInputSubmit);
1674
- }
1675
- // unbind key events, and cut/paste events
1676
- this.telInput.removeEventListener("input", this._handleInputEvent);
1677
- if (this._handleKeydownEvent) {
1678
- this.telInput.removeEventListener("keydown", this._handleKeydownEvent);
1679
- }
1680
- // remove attribute of id instance: data-intl-tel-input-id
1681
- this.telInput.removeAttribute("data-intl-tel-input-id");
1682
- // remove markup (but leave the original input)
1683
- var wrapper = this.telInput.parentNode;
1684
- wrapper.parentNode.insertBefore(this.telInput, wrapper);
1685
- wrapper.parentNode.removeChild(wrapper);
1686
- delete window.intlTelInputGlobals.instances[this.id];
1687
- }
1688
- }, {
1689
- key: "getExtension",
1690
- value: function getExtension() {
1691
- if (window.intlTelInputUtils) {
1692
- return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2);
1693
- }
1694
- return "";
1695
- }
1696
- }, {
1697
- key: "getNumber",
1698
- value: function getNumber(format) {
1699
- if (window.intlTelInputUtils) {
1700
- var iso2 = this.selectedCountryData.iso2;
1701
- return intlTelInputUtils.formatNumber(this._getFullNumber(), iso2, format);
1702
- }
1703
- return "";
1704
- }
1705
- }, {
1706
- key: "getNumberType",
1707
- value: function getNumberType() {
1708
- if (window.intlTelInputUtils) {
1709
- return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2);
1710
- }
1711
- return -99;
1712
- }
1713
- }, {
1714
- key: "getSelectedCountryData",
1715
- value: function getSelectedCountryData() {
1716
- return this.selectedCountryData;
1717
- }
1718
- }, {
1719
- key: "getValidationError",
1720
- value: function getValidationError() {
1721
- if (window.intlTelInputUtils) {
1722
- var iso2 = this.selectedCountryData.iso2;
1723
- return intlTelInputUtils.getValidationError(this._getFullNumber(), iso2);
1724
- }
1725
- return -99;
1726
- }
1727
- }, {
1728
- key: "isValidNumber",
1729
- value: function isValidNumber() {
1730
- var mobileOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1731
- var val = this._getFullNumber();
1732
- // return false for any alpha chars
1733
- 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)) {
1734
- return false;
1735
- }
1736
- return window.intlTelInputUtils ? intlTelInputUtils.isPossibleNumber(val, this.selectedCountryData.iso2, mobileOnly) : null;
1737
- }
1738
- }, {
1739
- key: "isValidNumberPrecise",
1740
- value: function isValidNumberPrecise() {
1741
- var val = this._getFullNumber();
1742
- // return false for any alpha chars
1743
- 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)) {
1744
- return false;
1745
- }
1746
- return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, this.selectedCountryData.iso2) : null;
1747
- }
1748
- }, {
1749
- key: "setCountry",
1750
- value: function setCountry(iso2) {
1751
- var iso2Lower = iso2.toLowerCase();
1752
- // check if already selected
1753
- if (this.selectedCountryData.iso2 !== iso2Lower) {
1754
- this._setCountry(iso2Lower);
1755
- this._updateDialCode(this.selectedCountryData.dialCode);
1756
- this._triggerCountryChange();
1757
- }
1758
- }
1759
- }, {
1760
- key: "setNumber",
1761
- value: function setNumber(number) {
1762
- // we must update the flag first, which updates this.selectedCountryData, which is used for
1763
- // formatting the number before displaying it
1764
- var flagChanged = this._updateFlagFromNumber(number);
1765
- this._updateValFromNumber(number);
1766
- if (flagChanged) {
1767
- this._triggerCountryChange();
1768
- }
1769
- }
1770
- }, {
1771
- key: "setPlaceholderNumberType",
1772
- value: function setPlaceholderNumberType(type) {
1773
- this.options.placeholderNumberType = type;
1774
- this._updatePlaceholder();
1775
- }
1776
- } ]);
1777
- return Iti;
1778
- }();
1779
- /********************
1780
- * STATIC METHODS
1781
- ********************/
1782
- // get the country data object
1783
- intlTelInputGlobals.getCountryData = function() {
1784
- return allCountries;
1785
- };
1786
- // inject a <script> element to load utils.js
1787
- var injectScript = function injectScript(path, handleSuccess, handleFailure) {
1788
- // inject a new script element into the page
1789
- var script = document.createElement("script");
1790
- script.onload = function() {
1791
- forEachInstance("handleUtils");
1792
- if (handleSuccess) {
1793
- handleSuccess();
1794
- }
1795
- };
1796
- script.onerror = function() {
1797
- forEachInstance("rejectUtilsScriptPromise");
1798
- if (handleFailure) {
1799
- handleFailure();
1800
- }
1801
- };
1802
- script.className = "iti-load-utils";
1803
- script.async = true;
1804
- script.src = path;
1805
- document.body.appendChild(script);
1806
- };
1807
- // load the utils script
1808
- intlTelInputGlobals.loadUtils = function(path) {
1809
- // 2 options:
1810
- // 1) not already started loading (start)
1811
- // 2) already started loading (do nothing - just wait for the onload callback to fire, which will
1812
- // trigger handleUtils on all instances, invoking their resolveUtilsScriptPromise functions)
1813
- if (!window.intlTelInputUtils && !window.intlTelInputGlobals.startedLoadingUtilsScript) {
1814
- // only do this once
1815
- window.intlTelInputGlobals.startedLoadingUtilsScript = true;
1816
- return new Promise(function(resolve, reject) {
1817
- return injectScript(path, resolve, reject);
1818
- });
2331
+ }
2332
+ }
2333
+ } else if (number.charAt(0) === "+" && numeric.length) {
2334
+ iso2 = "";
2335
+ } else if ((!number || number === "+") && !this.selectedCountryData.iso2) {
2336
+ iso2 = this.defaultCountry;
2337
+ }
2338
+ if (iso2 !== null) {
2339
+ return this._setCountry(iso2);
2340
+ }
2341
+ return false;
2342
+ }
2343
+ // remove highlighting from other list items and highlight the given item
2344
+ _highlightListItem(listItem, shouldFocus) {
2345
+ const prevItem = this.highlightedItem;
2346
+ if (prevItem) {
2347
+ prevItem.classList.remove("iti__highlight");
2348
+ prevItem.setAttribute("aria-selected", "false");
2349
+ }
2350
+ this.highlightedItem = listItem;
2351
+ this.highlightedItem.classList.add("iti__highlight");
2352
+ this.highlightedItem.setAttribute("aria-selected", "true");
2353
+ this.selectedCountry.setAttribute(
2354
+ "aria-activedescendant",
2355
+ listItem.getAttribute("id") || ""
2356
+ );
2357
+ if (this.options.countrySearch) {
2358
+ this.searchInput.setAttribute(
2359
+ "aria-activedescendant",
2360
+ listItem.getAttribute("id") || ""
2361
+ );
2362
+ }
2363
+ if (shouldFocus) {
2364
+ this.highlightedItem.focus();
2365
+ }
2366
+ }
2367
+ // find the country data for the given iso2 code
2368
+ // the ignoreOnlyCountriesOption is only used during init() while parsing the onlyCountries array
2369
+ _getCountryData(iso2, allowFail) {
2370
+ for (let i = 0; i < this.countries.length; i++) {
2371
+ if (this.countries[i].iso2 === iso2) {
2372
+ return this.countries[i];
2373
+ }
2374
+ }
2375
+ if (allowFail) {
2376
+ return null;
2377
+ }
2378
+ throw new Error(`No country data for '${iso2}'`);
2379
+ }
2380
+ // update the selected country, dial code (if showSelectedDialCode), placeholder, title, and active list item
2381
+ // Note: called from _setInitialState, _updateCountryFromNumber, _selectListItem, setCountry
2382
+ _setCountry(iso2) {
2383
+ const { allowDropdown, showSelectedDialCode, showFlags, countrySearch, i18n } = this.options;
2384
+ const prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {};
2385
+ this.selectedCountryData = iso2 ? this._getCountryData(iso2, false) || {} : {};
2386
+ if (this.selectedCountryData.iso2) {
2387
+ this.defaultCountry = this.selectedCountryData.iso2;
2388
+ }
2389
+ if (this.selectedCountryInner) {
2390
+ let flagClass = "";
2391
+ let a11yText = "";
2392
+ if (iso2) {
2393
+ if (showFlags) {
2394
+ flagClass = `iti__flag iti__${iso2}`;
2395
+ a11yText = `${this.selectedCountryData.name} +${this.selectedCountryData.dialCode}`;
2396
+ }
2397
+ } else {
2398
+ flagClass = "iti__flag iti__globe";
2399
+ a11yText = i18n.noCountrySelected || "No country selected";
2400
+ }
2401
+ this.selectedCountryInner.className = flagClass;
2402
+ this.selectedCountryA11yText.textContent = a11yText;
2403
+ }
2404
+ this._setSelectedCountryTitleAttribute(iso2, showSelectedDialCode);
2405
+ if (showSelectedDialCode) {
2406
+ const dialCode = this.selectedCountryData.dialCode ? `+${this.selectedCountryData.dialCode}` : "";
2407
+ this.selectedDialCode.innerHTML = dialCode;
2408
+ const selectedCountryWidth = this.selectedCountry.offsetWidth || this._getHiddenSelectedCountryWidth();
2409
+ if (this.isRTL) {
2410
+ this.telInput.style.paddingRight = `${selectedCountryWidth + 6}px`;
2411
+ } else {
2412
+ this.telInput.style.paddingLeft = `${selectedCountryWidth + 6}px`;
2413
+ }
2414
+ }
2415
+ this._updatePlaceholder();
2416
+ this._updateMaxLength();
2417
+ if (allowDropdown && !countrySearch) {
2418
+ const prevItem = this.activeItem;
2419
+ if (prevItem) {
2420
+ prevItem.classList.remove("iti__active");
2421
+ prevItem.setAttribute("aria-selected", "false");
2422
+ }
2423
+ if (iso2) {
2424
+ const nextItem = this.countryList.querySelector(
2425
+ `#iti-${this.id}__item-${iso2}-preferred`
2426
+ ) || this.countryList.querySelector(
2427
+ `#iti-${this.id}__item-${iso2}`
2428
+ );
2429
+ if (nextItem) {
2430
+ nextItem.setAttribute("aria-selected", "true");
2431
+ nextItem.classList.add("iti__active");
2432
+ this.activeItem = nextItem;
2433
+ }
2434
+ }
2435
+ }
2436
+ return prevCountry.iso2 !== iso2;
2437
+ }
2438
+ // update the maximum valid number length for the currently selected country
2439
+ _updateMaxLength() {
2440
+ if (this.options.strictMode && window.intlTelInputUtils) {
2441
+ if (this.selectedCountryData.iso2) {
2442
+ const numberType = window.intlTelInputUtils.numberType[this.options.placeholderNumberType];
2443
+ let exampleNumber = window.intlTelInputUtils.getExampleNumber(
2444
+ this.selectedCountryData.iso2,
2445
+ false,
2446
+ numberType,
2447
+ true
2448
+ );
2449
+ let validNumber = exampleNumber;
2450
+ while (window.intlTelInputUtils.isPossibleNumber(exampleNumber, this.selectedCountryData.iso2)) {
2451
+ validNumber = exampleNumber;
2452
+ exampleNumber += "0";
2453
+ }
2454
+ const coreNumber = window.intlTelInputUtils.getCoreNumber(validNumber, this.selectedCountryData.iso2);
2455
+ this.maxCoreNumberLength = coreNumber.length;
2456
+ } else {
2457
+ this.maxCoreNumberLength = null;
2458
+ }
2459
+ }
2460
+ }
2461
+ _setSelectedCountryTitleAttribute(iso2 = null, showSelectedDialCode) {
2462
+ if (!this.selectedCountry) {
2463
+ return;
2464
+ }
2465
+ let title;
2466
+ if (iso2 && !showSelectedDialCode) {
2467
+ title = `${this.selectedCountryData.name}: +${this.selectedCountryData.dialCode}`;
2468
+ } else if (iso2) {
2469
+ title = this.selectedCountryData.name;
2470
+ } else {
2471
+ title = "Unknown";
2472
+ }
2473
+ this.selectedCountry.setAttribute("title", title);
2474
+ }
2475
+ // when the input is in a hidden container during initialisation, we must inject some markup
2476
+ // into the end of the DOM to calculate the correct offsetWidth
2477
+ // NOTE: this is only used when showSelectedDialCode is enabled, so countryContainer and selectedCountry
2478
+ // will definitely exist
2479
+ _getHiddenSelectedCountryWidth() {
2480
+ if (this.telInput.parentNode) {
2481
+ const containerClone = this.telInput.parentNode.cloneNode(false);
2482
+ containerClone.style.visibility = "hidden";
2483
+ document.body.appendChild(containerClone);
2484
+ const countryContainerClone = this.countryContainer.cloneNode();
2485
+ containerClone.appendChild(countryContainerClone);
2486
+ const selectedCountryClone = this.selectedCountry.cloneNode(true);
2487
+ countryContainerClone.appendChild(selectedCountryClone);
2488
+ const width = selectedCountryClone.offsetWidth;
2489
+ document.body.removeChild(containerClone);
2490
+ return width;
2491
+ }
2492
+ return 0;
2493
+ }
2494
+ // update the input placeholder to an example number from the currently selected country
2495
+ _updatePlaceholder() {
2496
+ const {
2497
+ autoPlaceholder,
2498
+ placeholderNumberType,
2499
+ nationalMode,
2500
+ customPlaceholder
2501
+ } = this.options;
2502
+ const shouldSetPlaceholder = autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && autoPlaceholder === "polite";
2503
+ if (window.intlTelInputUtils && shouldSetPlaceholder) {
2504
+ const numberType = window.intlTelInputUtils.numberType[placeholderNumberType];
2505
+ let placeholder = this.selectedCountryData.iso2 ? window.intlTelInputUtils.getExampleNumber(
2506
+ this.selectedCountryData.iso2,
2507
+ nationalMode,
2508
+ numberType
2509
+ ) : "";
2510
+ placeholder = this._beforeSetNumber(placeholder);
2511
+ if (typeof customPlaceholder === "function") {
2512
+ placeholder = customPlaceholder(placeholder, this.selectedCountryData);
2513
+ }
2514
+ this.telInput.setAttribute("placeholder", placeholder);
2515
+ }
2516
+ }
2517
+ // called when the user selects a list item from the dropdown
2518
+ _selectListItem(listItem) {
2519
+ const countryChanged = this._setCountry(
2520
+ listItem.getAttribute("data-country-code")
2521
+ );
2522
+ this._closeDropdown();
2523
+ this._updateDialCode(listItem.getAttribute("data-dial-code"));
2524
+ this.telInput.focus();
2525
+ if (countryChanged) {
2526
+ this._triggerCountryChange();
2527
+ }
2528
+ }
2529
+ // close the dropdown and unbind any listeners
2530
+ _closeDropdown() {
2531
+ this.dropdownContent.classList.add("iti__hide");
2532
+ this.selectedCountry.setAttribute("aria-expanded", "false");
2533
+ this.selectedCountry.removeAttribute("aria-activedescendant");
2534
+ if (this.highlightedItem) {
2535
+ this.highlightedItem.setAttribute("aria-selected", "false");
2536
+ }
2537
+ if (this.options.countrySearch) {
2538
+ this.searchInput.removeAttribute("aria-activedescendant");
2539
+ }
2540
+ this.dropdownArrow.classList.remove("iti__arrow--up");
2541
+ document.removeEventListener("keydown", this._handleKeydownOnDropdown);
2542
+ if (this.options.countrySearch) {
2543
+ this.searchInput.removeEventListener("input", this._handleSearchChange);
2544
+ }
2545
+ document.documentElement.removeEventListener(
2546
+ "click",
2547
+ this._handleClickOffToClose
2548
+ );
2549
+ this.countryList.removeEventListener(
2550
+ "mouseover",
2551
+ this._handleMouseoverCountryList
2552
+ );
2553
+ this.countryList.removeEventListener("click", this._handleClickCountryList);
2554
+ if (this.options.dropdownContainer) {
2555
+ if (!this.options.useFullscreenPopup) {
2556
+ window.removeEventListener("scroll", this._handleWindowScroll);
2557
+ }
2558
+ if (this.dropdown.parentNode) {
2559
+ this.dropdown.parentNode.removeChild(this.dropdown);
2560
+ }
2561
+ }
2562
+ this._trigger("close:countrydropdown");
2563
+ }
2564
+ // check if an element is visible within it's container, else scroll until it is
2565
+ _scrollTo(element, middle) {
2566
+ const container = this.countryList;
2567
+ const windowTop = document.documentElement.scrollTop;
2568
+ const containerHeight = container.offsetHeight;
2569
+ const containerTop = container.getBoundingClientRect().top + windowTop;
2570
+ const containerBottom = containerTop + containerHeight;
2571
+ const elementHeight = element.offsetHeight;
2572
+ const elementTop = element.getBoundingClientRect().top + windowTop;
2573
+ const elementBottom = elementTop + elementHeight;
2574
+ let newScrollTop = elementTop - containerTop + container.scrollTop;
2575
+ const middleOffset = containerHeight / 2 - elementHeight / 2;
2576
+ if (elementTop < containerTop) {
2577
+ if (middle) {
2578
+ newScrollTop -= middleOffset;
2579
+ }
2580
+ container.scrollTop = newScrollTop;
2581
+ } else if (elementBottom > containerBottom) {
2582
+ if (middle) {
2583
+ newScrollTop += middleOffset;
2584
+ }
2585
+ const heightDifference = containerHeight - elementHeight;
2586
+ container.scrollTop = newScrollTop - heightDifference;
2587
+ }
2588
+ }
2589
+ // replace any existing dial code with the new one
2590
+ // Note: called from _selectListItem and setCountry
2591
+ _updateDialCode(newDialCodeBare) {
2592
+ const inputVal = this.telInput.value;
2593
+ const newDialCode = `+${newDialCodeBare}`;
2594
+ let newNumber;
2595
+ if (inputVal.charAt(0) === "+") {
2596
+ const prevDialCode = this._getDialCode(inputVal);
2597
+ if (prevDialCode) {
2598
+ newNumber = inputVal.replace(prevDialCode, newDialCode);
2599
+ } else {
2600
+ newNumber = newDialCode;
2601
+ }
2602
+ this.telInput.value = newNumber;
2603
+ }
2604
+ }
2605
+ // try and extract a valid international dial code from a full telephone number
2606
+ // Note: returns the raw string inc plus character and any whitespace/dots etc
2607
+ _getDialCode(number, includeAreaCode) {
2608
+ let dialCode = "";
2609
+ if (number.charAt(0) === "+") {
2610
+ let numericChars = "";
2611
+ for (let i = 0; i < number.length; i++) {
2612
+ const c = number.charAt(i);
2613
+ if (!isNaN(parseInt(c, 10))) {
2614
+ numericChars += c;
2615
+ if (includeAreaCode) {
2616
+ if (this.dialCodeToIso2Map[numericChars]) {
2617
+ dialCode = number.substr(0, i + 1);
2618
+ }
2619
+ } else {
2620
+ if (this.dialCodes[numericChars]) {
2621
+ dialCode = number.substr(0, i + 1);
2622
+ break;
2623
+ }
1819
2624
  }
1820
- return null;
1821
- };
1822
- // default options
1823
- intlTelInputGlobals.defaults = defaults;
1824
- // version
1825
- intlTelInputGlobals.version = "20.2.0";
1826
- // convenience wrapper
1827
- return function(input, options) {
1828
- var iti = new Iti(input, options);
1829
- iti._init();
1830
- input.setAttribute("data-intl-tel-input-id", iti.id);
1831
- window.intlTelInputGlobals.instances[iti.id] = iti;
1832
- return iti;
1833
- };
1834
- }();
1835
- });
2625
+ if (numericChars.length === this.dialCodeMaxLen) {
2626
+ break;
2627
+ }
2628
+ }
2629
+ }
2630
+ }
2631
+ return dialCode;
2632
+ }
2633
+ // get the input val, adding the dial code if showSelectedDialCode is enabled
2634
+ _getFullNumber() {
2635
+ const val = this.telInput.value.trim();
2636
+ const { dialCode } = this.selectedCountryData;
2637
+ let prefix;
2638
+ const numericVal = getNumeric(val);
2639
+ if (this.options.showSelectedDialCode && !this.options.nationalMode && val.charAt(0) !== "+" && dialCode && numericVal) {
2640
+ prefix = `+${dialCode}`;
2641
+ } else {
2642
+ prefix = "";
2643
+ }
2644
+ return prefix + val;
2645
+ }
2646
+ // remove the dial code if showSelectedDialCode is enabled
2647
+ // also cap the length if the input has a maxlength attribute
2648
+ _beforeSetNumber(fullNumber) {
2649
+ let number = fullNumber;
2650
+ if (this.options.showSelectedDialCode) {
2651
+ let dialCode = this._getDialCode(number);
2652
+ if (dialCode) {
2653
+ dialCode = `+${this.selectedCountryData.dialCode}`;
2654
+ const start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
2655
+ number = number.substr(start);
2656
+ }
2657
+ }
2658
+ return this._cap(number);
2659
+ }
2660
+ // trigger the 'countrychange' event
2661
+ _triggerCountryChange() {
2662
+ this._trigger("countrychange");
2663
+ }
2664
+ // format the number as the user types
2665
+ _formatNumberAsYouType() {
2666
+ const val = this._getFullNumber();
2667
+ const result = window.intlTelInputUtils ? window.intlTelInputUtils.formatNumberAsYouType(val, this.selectedCountryData.iso2) : val;
2668
+ const { dialCode } = this.selectedCountryData;
2669
+ if (this.options.showSelectedDialCode && !this.options.nationalMode && this.telInput.value.charAt(0) !== "+" && result.includes(`+${dialCode}`)) {
2670
+ const afterDialCode = result.split(`+${dialCode}`)[1] || "";
2671
+ return afterDialCode.trim();
2672
+ }
2673
+ return result;
2674
+ }
2675
+ //**************************
2676
+ //* SECRET PUBLIC METHODS
2677
+ //**************************
2678
+ // this is called when the geoip call returns
2679
+ handleAutoCountry() {
2680
+ if (this.options.initialCountry === "auto" && window.intlTelInputGlobals.autoCountry) {
2681
+ this.defaultCountry = window.intlTelInputGlobals.autoCountry;
2682
+ if (!this.telInput.value) {
2683
+ this.setCountry(this.defaultCountry);
2684
+ }
2685
+ this.resolveAutoCountryPromise();
2686
+ }
2687
+ }
2688
+ // this is called when the utils request completes
2689
+ handleUtils() {
2690
+ if (window.intlTelInputUtils) {
2691
+ if (this.telInput.value) {
2692
+ this._updateValFromNumber(this.telInput.value);
2693
+ }
2694
+ if (this.selectedCountryData.iso2) {
2695
+ this._updatePlaceholder();
2696
+ this._updateMaxLength();
2697
+ }
2698
+ }
2699
+ this.resolveUtilsScriptPromise();
2700
+ }
2701
+ //********************
2702
+ //* PUBLIC METHODS
2703
+ //********************
2704
+ // remove plugin
2705
+ destroy() {
2706
+ if (this.options.allowDropdown) {
2707
+ this._closeDropdown();
2708
+ this.selectedCountry.removeEventListener(
2709
+ "click",
2710
+ this._handleClickSelectedCountry
2711
+ );
2712
+ this.countryContainer.removeEventListener(
2713
+ "keydown",
2714
+ this._handleCountryContainerKeydown
2715
+ );
2716
+ const label = this.telInput.closest("label");
2717
+ if (label) {
2718
+ label.removeEventListener("click", this._handleLabelClick);
2719
+ }
2720
+ }
2721
+ const { form } = this.telInput;
2722
+ if (this._handleHiddenInputSubmit && form) {
2723
+ form.removeEventListener("submit", this._handleHiddenInputSubmit);
2724
+ }
2725
+ this.telInput.removeEventListener("input", this._handleInputEvent);
2726
+ if (this._handleKeydownEvent) {
2727
+ this.telInput.removeEventListener("keydown", this._handleKeydownEvent);
2728
+ }
2729
+ this.telInput.removeAttribute("data-intl-tel-input-id");
2730
+ const wrapper = this.telInput.parentNode;
2731
+ wrapper?.parentNode?.insertBefore(this.telInput, wrapper);
2732
+ wrapper?.parentNode?.removeChild(wrapper);
2733
+ delete window.intlTelInputGlobals.instances[this.id];
2734
+ }
2735
+ // get the extension from the current number
2736
+ getExtension() {
2737
+ if (window.intlTelInputUtils) {
2738
+ return window.intlTelInputUtils.getExtension(
2739
+ this._getFullNumber(),
2740
+ this.selectedCountryData.iso2
2741
+ );
2742
+ }
2743
+ return "";
2744
+ }
2745
+ // format the number to the given format
2746
+ getNumber(format) {
2747
+ if (window.intlTelInputUtils) {
2748
+ const { iso2 } = this.selectedCountryData;
2749
+ return window.intlTelInputUtils.formatNumber(
2750
+ this._getFullNumber(),
2751
+ iso2,
2752
+ format
2753
+ );
2754
+ }
2755
+ return "";
2756
+ }
2757
+ // get the type of the entered number e.g. landline/mobile
2758
+ getNumberType() {
2759
+ if (window.intlTelInputUtils) {
2760
+ return window.intlTelInputUtils.getNumberType(
2761
+ this._getFullNumber(),
2762
+ this.selectedCountryData.iso2
2763
+ );
2764
+ }
2765
+ return -99;
2766
+ }
2767
+ // get the country data for the currently selected country
2768
+ getSelectedCountryData() {
2769
+ return this.selectedCountryData;
2770
+ }
2771
+ // get the validation error
2772
+ getValidationError() {
2773
+ if (window.intlTelInputUtils) {
2774
+ const { iso2 } = this.selectedCountryData;
2775
+ return window.intlTelInputUtils.getValidationError(this._getFullNumber(), iso2);
2776
+ }
2777
+ return -99;
2778
+ }
2779
+ // validate the input val - assumes the global function isPossibleNumber (from utilsScript)
2780
+ isValidNumber(mobileOnly = true) {
2781
+ const val = this._getFullNumber();
2782
+ if (/\p{L}/u.test(val)) {
2783
+ return false;
2784
+ }
2785
+ return window.intlTelInputUtils ? window.intlTelInputUtils.isPossibleNumber(val, this.selectedCountryData.iso2, mobileOnly) : null;
2786
+ }
2787
+ // validate the input val (precise) - assumes the global function isValidNumber (from utilsScript)
2788
+ isValidNumberPrecise() {
2789
+ const val = this._getFullNumber();
2790
+ if (/\p{L}/u.test(val)) {
2791
+ return false;
2792
+ }
2793
+ return window.intlTelInputUtils ? window.intlTelInputUtils.isValidNumber(val, this.selectedCountryData.iso2) : null;
2794
+ }
2795
+ // update the selected country, and update the input val accordingly
2796
+ setCountry(iso2) {
2797
+ const iso2Lower = iso2.toLowerCase();
2798
+ if (this.selectedCountryData.iso2 !== iso2Lower) {
2799
+ this._setCountry(iso2Lower);
2800
+ this._updateDialCode(this.selectedCountryData.dialCode);
2801
+ this._triggerCountryChange();
2802
+ }
2803
+ }
2804
+ // set the input value and update the country
2805
+ setNumber(number) {
2806
+ const countryChanged = this._updateCountryFromNumber(number);
2807
+ this._updateValFromNumber(number);
2808
+ if (countryChanged) {
2809
+ this._triggerCountryChange();
2810
+ }
2811
+ }
2812
+ // set the placeholder number typ
2813
+ setPlaceholderNumberType(type) {
2814
+ this.options.placeholderNumberType = type;
2815
+ this._updatePlaceholder();
2816
+ }
2817
+ };
2818
+ var injectScript = (path, handleSuccess, handleFailure) => {
2819
+ const script = document.createElement("script");
2820
+ script.onload = () => {
2821
+ forEachInstance("handleUtils");
2822
+ if (handleSuccess) {
2823
+ handleSuccess();
2824
+ }
2825
+ };
2826
+ script.onerror = () => {
2827
+ forEachInstance("rejectUtilsScriptPromise");
2828
+ if (handleFailure) {
2829
+ handleFailure();
2830
+ }
2831
+ };
2832
+ script.className = "iti-load-utils";
2833
+ script.async = true;
2834
+ script.src = path;
2835
+ document.body.appendChild(script);
2836
+ };
2837
+ var loadUtils = (path) => {
2838
+ if (!window.intlTelInputUtils && !window.intlTelInputGlobals.startedLoadingUtilsScript) {
2839
+ window.intlTelInputGlobals.startedLoadingUtilsScript = true;
2840
+ return new Promise(
2841
+ (resolve, reject) => injectScript(path, resolve, reject)
2842
+ );
2843
+ }
2844
+ return null;
2845
+ };
2846
+ if (typeof window === "object") {
2847
+ const intlTelInputGlobals = {
2848
+ defaults,
2849
+ // using a global like this allows us to mock it in the tests
2850
+ documentReady: () => document.readyState === "complete",
2851
+ // get the country data object
2852
+ getCountryData: () => data_default,
2853
+ // a getter for the plugin instance
2854
+ getInstance: (input) => {
2855
+ const id2 = input.getAttribute("data-intl-tel-input-id");
2856
+ return id2 ? intlTelInputGlobals.instances[id2] : null;
2857
+ },
2858
+ // a map from instance ID to instance object
2859
+ instances: {},
2860
+ loadUtils,
2861
+ version: "21.0.0"
2862
+ };
2863
+ window.intlTelInputGlobals = intlTelInputGlobals;
2864
+ }
2865
+ var intlTelInput = (input, options) => {
2866
+ const iti = new Iti(input, options);
2867
+ iti._init();
2868
+ input.setAttribute("data-intl-tel-input-id", iti.id.toString());
2869
+ window.intlTelInputGlobals.instances[iti.id] = iti;
2870
+ return iti;
2871
+ };
2872
+ var intlTelInput_default = intlTelInput;
2873
+ return __toCommonJS(intlTelInput_exports);
2874
+ })();
2875
+
2876
+ // UMD
2877
+ return factoryOutput.default;
2878
+ }));