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