1/* 2 * International Telephone Input v16.0.0 3 * https://github.com/jackocnr/intl-tel-input.git 4 * Licensed under the MIT license 5 */ 6 7// wrap in UMD 8(function (factory) { 9 var intlTelInput = factory(window, document); 10 if (typeof module === "object" && module.exports) module.exports = intlTelInput; 11 else window.intlTelInput = intlTelInput; 12})(function (window, document, undefined) { 13 "use strict"; 14 return (function () { 15 // Array of country objects for the flag dropdown. 16 // Here is the criteria for the plugin to support a given country/territory 17 // - It has an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 18 // - 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 19 // - It has a flag in the region-flags project: https://github.com/behdad/region-flags/tree/gh-pages/png 20 // - It is supported by libphonenumber (it must be listed on this page): https://github.com/googlei18n/libphonenumber/blob/master/resources/ShortNumberMetadata.xml 21 // Each country array has the following information: 22 // [ 23 // Country name, 24 // iso2 code, 25 // International dial code, 26 // Order (if >1 country with same dial code), 27 // Area codes 28 // ] 29 var allCountries = [ 30 ["Afghanistan (â«Ø§ÙØºØ§ÙØ³ØªØ§Ùâ¬â)", "af", "93"], 31 ["Albania (Shqipëri)", "al", "355"], 32 ["Algeria (â«Ø§Ùجزائرâ¬â)", "dz", "213"], 33 ["American Samoa", "as", "1", 5, ["684"]], 34 ["Andorra", "ad", "376"], 35 ["Angola", "ao", "244"], 36 ["Anguilla", "ai", "1", 6, ["264"]], 37 ["Antigua and Barbuda", "ag", "1", 7, ["268"]], 38 ["Argentina", "ar", "54"], 39 ["Armenia (ÕÕ¡ÕµÕ¡Õ½Õ¿Õ¡Õ¶)", "am", "374"], 40 ["Aruba", "aw", "297"], 41 ["Australia", "au", "61", 0], 42 ["Austria (Ãsterreich)", "at", "43"], 43 ["Azerbaijan (AzÉrbaycan)", "az", "994"], 44 ["Bahamas", "bs", "1", 8, ["242"]], 45 ["Bahrain (â«Ø§ÙØ¨ØØ±ÙÙâ¬â)", "bh", "973"], 46 ["Bangladesh (বাà¦à¦²à¦¾à¦¦à§à¦¶)", "bd", "880"], 47 ["Barbados", "bb", "1", 9, ["246"]], 48 ["Belarus (ÐелаÑÑÑÑ)", "by", "375"], 49 ["Belgium (België)", "be", "32"], 50 ["Belize", "bz", "501"], 51 ["Benin (Bénin)", "bj", "229"], 52 ["Bermuda", "bm", "1", 10, ["441"]], 53 ["Bhutan (འà½à¾²à½´à½)", "bt", "975"], 54 ["Bolivia", "bo", "591"], 55 ["Bosnia and Herzegovina (ÐоÑна и ХеÑÑеговина)", "ba", "387"], 56 ["Botswana", "bw", "267"], 57 ["Brazil (Brasil)", "br", "55"], 58 ["British Indian Ocean Territory", "io", "246"], 59 ["British Virgin Islands", "vg", "1", 11, ["284"]], 60 ["Brunei", "bn", "673"], 61 ["Bulgaria (ÐÑлгаÑиÑ)", "bg", "359"], 62 ["Burkina Faso", "bf", "226"], 63 ["Burundi (Uburundi)", "bi", "257"], 64 ["Cambodia (ááááá»áá¶)", "kh", "855"], 65 ["Cameroon (Cameroun)", "cm", "237"], 66 [ 67 "Canada", 68 "ca", 69 "1", 70 1, 71 [ 72 "204", 73 "226", 74 "236", 75 "249", 76 "250", 77 "289", 78 "306", 79 "343", 80 "365", 81 "387", 82 "403", 83 "416", 84 "418", 85 "431", 86 "437", 87 "438", 88 "450", 89 "506", 90 "514", 91 "519", 92 "548", 93 "579", 94 "581", 95 "587", 96 "604", 97 "613", 98 "639", 99 "647", 100 "672", 101 "705", 102 "709", 103 "742", 104 "778", 105 "780", 106 "782", 107 "807", 108 "819", 109 "825", 110 "867", 111 "873", 112 "902", 113 "905", 114 ], 115 ], 116 ["Cape Verde (Kabu Verdi)", "cv", "238"], 117 ["Caribbean Netherlands", "bq", "599", 1, ["3", "4", "7"]], 118 ["Cayman Islands", "ky", "1", 12, ["345"]], 119 ["Central African Republic (République centrafricaine)", "cf", "236"], 120 ["Chad (Tchad)", "td", "235"], 121 ["Chile", "cl", "56"], 122 ["China (ä¸å½)", "cn", "86"], 123 ["Christmas Island", "cx", "61", 2], 124 ["Cocos (Keeling) Islands", "cc", "61", 1], 125 ["Colombia", "co", "57"], 126 ["Comoros (â«Ø¬Ø²Ø± اÙÙ٠رâ¬â)", "km", "269"], 127 ["Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)", "cd", "243"], 128 ["Congo (Republic) (Congo-Brazzaville)", "cg", "242"], 129 ["Cook Islands", "ck", "682"], 130 ["Costa Rica", "cr", "506"], 131 ["Côte dâIvoire", "ci", "225"], 132 ["Croatia (Hrvatska)", "hr", "385"], 133 ["Cuba", "cu", "53"], 134 ["Curaçao", "cw", "599", 0], 135 ["Cyprus (ÎÏÏÏοÏ)", "cy", "357"], 136 ["Czech Republic (Äeská republika)", "cz", "420"], 137 ["Denmark (Danmark)", "dk", "45"], 138 ["Djibouti", "dj", "253"], 139 ["Dominica", "dm", "1", 13, ["767"]], 140 ["Dominican Republic (República Dominicana)", "do", "1", 2, ["809", "829", "849"]], 141 ["Ecuador", "ec", "593"], 142 ["Egypt (â«Ù صرâ¬â)", "eg", "20"], 143 ["El Salvador", "sv", "503"], 144 ["Equatorial Guinea (Guinea Ecuatorial)", "gq", "240"], 145 ["Eritrea", "er", "291"], 146 ["Estonia (Eesti)", "ee", "372"], 147 ["Ethiopia", "et", "251"], 148 ["Falkland Islands (Islas Malvinas)", "fk", "500"], 149 ["Faroe Islands (Føroyar)", "fo", "298"], 150 ["Fiji", "fj", "679"], 151 ["Finland (Suomi)", "fi", "358", 0], 152 ["France", "fr", "33"], 153 ["French Guiana (Guyane française)", "gf", "594"], 154 ["French Polynesia (Polynésie française)", "pf", "689"], 155 ["Gabon", "ga", "241"], 156 ["Gambia", "gm", "220"], 157 ["Georgia (á¡áá¥áá ááááá)", "ge", "995"], 158 ["Germany (Deutschland)", "de", "49"], 159 ["Ghana (Gaana)", "gh", "233"], 160 ["Gibraltar", "gi", "350"], 161 ["Greece (Îλλάδα)", "gr", "30"],
162 ["Greenland (Kalaallit Nunaat)", "gl", "299"], 163 ["Grenada", "gd", "1", 14, ["473"]], 164 ["Guadeloupe", "gp", "590", 0], 165 ["Guam", "gu", "1", 15, ["671"]], 166 ["Guatemala", "gt", "502"], 167 ["Guernsey", "gg", "44", 1, ["1481", "7781", "7839", "7911"]], 168 ["Guinea (Guinée)", "gn", "224"], 169 ["Guinea-Bissau (Guiné Bissau)", "gw", "245"], 170 ["Guyana", "gy", "592"], 171 ["Haiti", "ht", "509"], 172 ["Honduras", "hn", "504"], 173 ["Hong Kong (馿¸¯)", "hk", "852"], 174 ["Hungary (Magyarország)", "hu", "36"], 175 ["Iceland (Ãsland)", "is", "354"], 176 ["India (à¤à¤¾à¤°à¤¤)", "in", "91"], 177 ["Indonesia", "id", "62"], 178 ["Iran (â«Ø§ÛراÙâ¬â)", "ir", "98"], 179 ["Iraq (â«Ø§ÙعراÙâ¬â)", "iq", "964"], 180 ["Ireland", "ie", "353"], 181 ["Isle of Man", "im", "44", 2, ["1624", "74576", "7524", "7924", "7624"]], 182 ["Israel (â«×שר××â¬â)", "il", "972"], 183 ["Italy (Italia)", "it", "39", 0], 184 ["Jamaica", "jm", "1", 4, ["876", "658"]], 185 ["Japan (æ¥æ¬)", "jp", "81"], 186 ["Jersey", "je", "44", 3, ["1534", "7509", "7700", "7797", "7829", "7937"]], 187 ["Jordan (â«Ø§ÙأردÙâ¬â)", "jo", "962"], 188 ["Kazakhstan (ÐÐ°Ð·Ð°Ñ ÑÑан)", "kz", "7", 1, ["33", "7"]], 189 ["Kenya", "ke", "254"], 190 ["Kiribati", "ki", "686"], 191 ["Kosovo", "xk", "383"], 192 ["Kuwait (â«Ø§ÙÙÙÙØªâ¬â)", "kw", "965"], 193 ["Kyrgyzstan (ÐÑÑгÑзÑÑан)", "kg", "996"], 194 ["Laos (ລາວ)", "la", "856"], 195 ["Latvia (Latvija)", "lv", "371"], 196 ["Lebanon (â«ÙØ¨ÙØ§Ùâ¬â)", "lb", "961"], 197 ["Lesotho", "ls", "266"], 198 ["Liberia", "lr", "231"], 199 ["Libya (â«ÙÙØ¨Ùاâ¬â)", "ly", "218"], 200 ["Liechtenstein", "li", "423"], 201 ["Lithuania (Lietuva)", "lt", "370"], 202 ["Luxembourg", "lu", "352"], 203 ["Macau (æ¾³é)", "mo", "853"], 204 ["Macedonia (FYROM) (ÐакедониÑа)", "mk", "389"], 205 ["Madagascar (Madagasikara)", "mg", "261"], 206 ["Malawi", "mw", "265"], 207 ["Malaysia", "my", "60"], 208 ["Maldives", "mv", "960"], 209 ["Mali", "ml", "223"], 210 ["Malta", "mt", "356"], 211 ["Marshall Islands", "mh", "692"], 212 ["Martinique", "mq", "596"], 213 ["Mauritania (â«Ù ÙØ±ÙتاÙÙØ§â¬â)", "mr", "222"], 214 ["Mauritius (Moris)", "mu", "230"], 215 ["Mayotte", "yt", "262", 1, ["269", "639"]], 216 ["Mexico (México)", "mx", "52"], 217 ["Micronesia", "fm", "691"], 218 ["Moldova (Republica Moldova)", "md", "373"], 219 ["Monaco", "mc", "377"], 220 ["Mongolia (Ðонгол)", "mn", "976"], 221 ["Montenegro (Crna Gora)", "me", "382"], 222 ["Montserrat", "ms", "1", 16, ["664"]], 223 ["Morocco (â«Ø§Ù٠غربâ¬â)", "ma", "212", 0], 224 ["Mozambique (Moçambique)", "mz", "258"], 225 ["Myanmar (Burma) (áá¼ááºáá¬)", "mm", "95"], 226 ["Namibia (Namibië)", "na", "264"], 227 ["Nauru", "nr", "674"], 228 ["Nepal (नà¥à¤ªà¤¾à¤²)", "np", "977"], 229 ["Netherlands (Nederland)", "nl", "31"], 230 ["New Caledonia (Nouvelle-Calédonie)", "nc", "687"], 231 ["New Zealand", "nz", "64"], 232 ["Nicaragua", "ni", "505"], 233 ["Niger (Nijar)", "ne", "227"], 234 ["Nigeria", "ng", "234"], 235 ["Niue", "nu", "683"], 236 ["Norfolk Island", "nf", "672"], 237 ["North Korea (ì¡°ì 민주주ì ì¸ë¯¼ ê³µíêµ)", "kp", "850"], 238 ["Northern Mariana Islands", "mp", "1", 17, ["670"]], 239 ["Norway (Norge)", "no", "47", 0], 240 ["Oman (â«Ø¹Ù٠اÙâ¬â)", "om", "968"], 241 ["Pakistan (â«Ù¾Ø§Ú©Ø³ØªØ§Ùâ¬â)", "pk", "92"], 242 ["Palau", "pw", "680"], 243 ["Palestine (â«ÙÙØ³Ø·ÙÙâ¬â)", "ps", "970"], 244 ["Panama (Panamá)", "pa", "507"], 245 ["Papua New Guinea", "pg", "675"], 246 ["Paraguay", "py", "595"], 247 ["Peru (Perú)", "pe", "51"], 248 ["Philippines", "ph", "63"], 249 ["Poland (Polska)", "pl", "48"], 250 ["Portugal", "pt", "351"], 251 ["Puerto Rico", "pr", "1", 3, ["787", "939"]], 252 ["Qatar (â«Ùطرâ¬â)", "qa", "974"], 253 ["Réunion (La Réunion)", "re", "262", 0], 254 ["Romania (România)", "ro", "40"], 255 ["Russia (РоÑÑиÑ)", "ru", "7", 0], 256 ["Rwanda", "rw", "250"], 257 ["Saint Barthélemy", "bl", "590", 1], 258 ["Saint Helena", "sh", "290"], 259 ["Saint Kitts and Nevis", "kn", "1", 18, ["869"]], 260 ["Saint Lucia", "lc", "1", 19, ["758"]], 261 ["Saint Martin (Saint-Martin (partie française))", "mf", "590", 2], 262 ["Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)", "pm", "508"], 263 ["Saint Vincent and the Grenadines", "vc", "1", 20, ["784"]], 264 ["Samoa", "ws", "685"], 265 ["San Marino", "sm", "378"], 266 ["São Tomé and PrÃncipe (São Tomé e PrÃncipe)", "st", "239"], 267 ["Saudi Arabia (â«Ø§ÙÙ Ù ÙÙØ© Ø§ÙØ¹Ø±Ø¨ÙØ© Ø§ÙØ³Ø¹ÙØ¯ÙØ©â¬â)", "sa", "966"], 268 ["Senegal (Sénégal)", "sn", "221"], 269 ["Serbia (СÑбиÑа)", "rs", "381"], 270 ["Seychelles", "sc", "248"],
271 ["Sierra Leone", "sl", "232"], 272 ["Singapore", "sg", "65"], 273 ["Sint Maarten", "sx", "1", 21, ["721"]], 274 ["Slovakia (Slovensko)", "sk", "421"], 275 ["Slovenia (Slovenija)", "si", "386"], 276 ["Solomon Islands", "sb", "677"], 277 ["Somalia (Soomaaliya)", "so", "252"], 278 ["South Africa", "za", "27"], 279 ["South Korea (ëí민êµ)", "kr", "82"], 280 ["South Sudan (â«Ø¬ÙÙØ¨ Ø§ÙØ³ÙداÙâ¬â)", "ss", "211"], 281 ["Spain (España)", "es", "34"], 282 ["Sri Lanka (à·à·âර෠ලà¶à¶à·à·)", "lk", "94"], 283 ["Sudan (â«Ø§ÙØ³ÙØ¯Ø§Ùâ¬â)", "sd", "249"], 284 ["Suriname", "sr", "597"], 285 ["Svalbard and Jan Mayen", "sj", "47", 1, ["79"]], 286 ["Swaziland", "sz", "268"], 287 ["Sweden (Sverige)", "se", "46"], 288 ["Switzerland (Schweiz)", "ch", "41"], 289 ["Syria (â«Ø³ÙØ±ÙØ§â¬â)", "sy", "963"], 290 ["Taiwan (å°ç£)", "tw", "886"], 291 ["Tajikistan", "tj", "992"], 292 ["Tanzania", "tz", "255"], 293 ["Thailand (à¹à¸à¸¢)", "th", "66"], 294 ["Timor-Leste", "tl", "670"], 295 ["Togo", "tg", "228"], 296 ["Tokelau", "tk", "690"], 297 ["Tonga", "to", "676"], 298 ["Trinidad and Tobago", "tt", "1", 22, ["868"]], 299 ["Tunisia (â«ØªÙÙØ³â¬â)", "tn", "216"], 300 ["Turkey (Türkiye)", "tr", "90"], 301 ["Turkmenistan", "tm", "993"], 302 ["Turks and Caicos Islands", "tc", "1", 23, ["649"]], 303 ["Tuvalu", "tv", "688"], 304 ["U.S. Virgin Islands", "vi", "1", 24, ["340"]], 305 ["Uganda", "ug", "256"], 306 ["Ukraine (УкÑаÑна)", "ua", "380"], 307 ["United Arab Emirates (â«Ø§Ùإ٠ارات Ø§ÙØ¹Ø±Ø¨ÙØ© اÙÙ ØªØØ¯Ø©â¬â)", "ae", "971"], 308 ["United Kingdom", "gb", "44", 0], 309 ["United States", "us", "1", 0], 310 ["Uruguay", "uy", "598"], 311 ["Uzbekistan (OÊ»zbekiston)", "uz", "998"], 312 ["Vanuatu", "vu", "678"], 313 ["Vatican City (Città del Vaticano)", "va", "39", 1, ["06698"]], 314 ["Venezuela", "ve", "58"], 315 ["Vietnam (Viá»t Nam)", "vn", "84"], 316 ["Wallis and Futuna (Wallis-et-Futuna)", "wf", "681"], 317 ["Western Sahara (â«Ø§ÙØµØØ±Ø§Ø¡ Ø§ÙØºØ±Ø¨ÙØ©â¬â)", "eh", "212", 1, ["5288", "5289"]], 318 ["Yemen (â«Ø§ÙÙÙ Ùâ¬â)", "ye", "967"], 319 ["Zambia", "zm", "260"], 320 ["Zimbabwe", "zw", "263"], 321 ["à land Islands", "ax", "358", 1, ["18"]], 322 ]; 323 // loop over all of the countries above, restructuring the data to be objects with named keys 324 for (var i = 0; i < allCountries.length; i++) { 325 var c = allCountries[i]; 326 allCountries[i] = { 327 name: c[0], 328 iso2: c[1], 329 dialCode: c[2], 330 priority: c[3] || 0, 331 areaCodes: c[4] || null, 332 }; 333 } 334 ("use strict"); 335 function _classCallCheck(instance, Constructor) { 336 if (!(instance instanceof Constructor)) { 337 throw new TypeError("Cannot call a class as a function"); 338 } 339 } 340 function _defineProperties(target, props) { 341 for (var i = 0; i < props.length; i++) { 342 var descriptor = props[i]; 343 descriptor.enumerable = descriptor.enumerable || false; 344 descriptor.configurable = true; 345 if ("value" in descriptor) descriptor.writable = true; 346 Object.defineProperty(target, descriptor.key, descriptor); 347 } 348 } 349 function _createClass(Constructor, protoProps, staticProps) { 350 if (protoProps) _defineProperties(Constructor.prototype, protoProps); 351 if (staticProps) _defineProperties(Constructor, staticProps); 352 return Constructor; 353 } 354 window.intlTelInputGlobals = { 355 getInstance: function getInstance(input) { 356 var id = input.getAttribute("data-intl-tel-input-id"); 357 return window.intlTelInputGlobals.instances[id]; 358 }, 359 instances: {}, 360 }; 361 // these vars persist through all instances of the plugin 362 var id = 0; 363 var defaults = { 364 // whether or not to allow the dropdown 365 allowDropdown: true, 366 // if there is just a dial code in the input: remove it on blur 367 autoHideDialCode: true, 368 // add a placeholder in the input with an example number for the selected country 369 autoPlaceholder: "polite", 370 // modify the parentClass 371 customContainer: "", 372 // modify the auto placeholder 373 customPlaceholder: null, 374 // append menu to specified element 375 dropdownContainer: null, 376 // don't display these countries 377 excludeCountries: [], 378 // format the input value during initialisation and on setNumber 379 formatOnDisplay: true, 380 // geoIp lookup function 381 geoIpLookup: null, 382 // inject a hidden input with this name, and on submit, populate it with the result of getNumber 383 hiddenInput: "", 384 // initial country 385 initialCountry: "", 386 // localized country names e.g. { 'de': 'Deutschland' } 387 localizedCountries: null, 388 // don't insert international dial codes 389 nationalMode: true, 390 // display only these countries 391 onlyCountries: [], 392 // number type to use for placeholders 393 placeholderNumberType: "MOBILE", 394 // the countries at the top of the list. defaults to united states and united kingdom 395 preferredCountries: ["us", "gb"], 396 // display the country dial code next to the selected flag so it's not part of the typed number 397 separateDialCode: false, 398 // specify the path to the libphonenumber script to enable validation/formatting 399 utilsScript: "", 400 }; 401 // https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#Non-geographic_area_codes 402 var regionlessNanpNumbers = [ 403 "800", 404 "822", 405 "833", 406 "844", 407 "855", 408 "866", 409 "877", 410 "880", 411 "881", 412 "882", 413 "883", 414 "884", 415 "885", 416 "886", 417 "887", 418 "888", 419 "889", 420 ]; 421 // keep track of if the window.load event has fired as impossible to check after the fact 422 window.addEventListener("load", function () { 423 // UPDATE: use a public static field so we can fudge it in the tests 424 window.intlTelInputGlobals.windowLoaded = true; 425 }); 426 // utility function to iterate over an object. can't use Object.entries or native forEac
426h because 427 // of IE11 428 var forEachProp = function forEachProp(obj, callback) { 429 var keys = Object.keys(obj); 430 for (var i = 0; i < keys.length; i++) { 431 callback(keys[i], obj[keys[i]]); 432 } 433 }; 434 // run a method on each instance of the plugin 435 var forEachInstance = function forEachInstance(method) { 436 forEachProp(window.intlTelInputGlobals.instances, function (key) { 437 window.intlTelInputGlobals.instances[key][method](); 438 }); 439 }; 440 // this is our plugin class that we will create an instance of 441 // eslint-disable-next-line no-unused-vars 442 var Iti = 443 /*#__PURE__*/ 444 (function () { 445 function Iti(input, options) { 446 var _this = this; 447 _classCallCheck(this, Iti); 448 this.id = id++; 449 this.telInput = input; 450 this.activeItem = null; 451 this.highlightedItem = null; 452 // process specified options / defaults 453 // alternative to Object.assign, which isn't supported by IE11 454 var customOptions = options || {}; 455 this.options = {}; 456 forEachProp(defaults, function (key, value) { 457 _this.options[key] = customOptions.hasOwnProperty(key) ? customOptions[key] : value; 458 }); 459 this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder")); 460 } 461 _createClass(Iti, [ 462 { 463 key: "_init", 464 value: function _init() { 465 var _this2 = this; 466 // if in nationalMode, disable options relating to dial codes 467 if (this.options.nationalMode) this.options.autoHideDialCode = false; 468 // if separateDialCode then doesn't make sense to A) insert dial code into input 469 // (autoHideDialCode), and B) display national numbers (because we're displaying the country 470 // dial code next to them) 471 if (this.options.separateDialCode) { 472 this.options.autoHideDialCode = this.options.nationalMode = false; 473 } 474 // we cannot just test screen size as some smartphones/website meta tags will report desktop 475 // resolutions 476 // Note: for some reason jasmine breaks if you put this in the main Plugin function with the 477 // rest of these declarations 478 // Note: to target Android Mobiles (and not Tablets), we must find 'Android' and 'Mobile' 479 this.isMobile = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test( 480 navigator.userAgent 481 ); 482 if (this.isMobile) { 483 // trigger the mobile dropdown css 484 document.body.classList.add("iti-mobile"); 485 // on mobile, we want a full screen dropdown, so we must append it to the body 486 if (!this.options.dropdownContainer) this.options.dropdownContainer = document.body; 487 } 488 // these promises get resolved when their individual requests complete 489 // this way the dev can do something like iti.promise.then(...) to know when all requests are 490 // complete 491 if (typeof Promise !== "undefined") { 492 var autoCountryPromise = new Promise(function (resolve, reject) { 493 _this2.resolveAutoCountryPromise = resolve; 494 _this2.rejectAutoCountryPromise = reject; 495 }); 496 var utilsScriptPromise = new Promise(function (resolve, reject) { 497 _this2.resolveUtilsScriptPromise = resolve; 498 _this2.rejectUtilsScriptPromise = reject; 499 }); 500 this.promise = Promise.all([autoCountryPromise, utilsScriptPromise]); 501 } else { 502 // prevent errors when Promise doesn't exist 503 this.resolveAutoCountryPromise = this.rejectAutoCountryPromise = function () {}; 504 this.resolveUtilsScriptPromise = this.rejectUtilsScriptPromise = function () {}; 505 } 506 // in various situations there could be no country selected initially, but we need to be able 507 // to assume this variable exists 508 this.selectedCountryData = {}; 509 // process all the data: onlyCountries, excludeCountries, preferredCountries etc 510 this._processCountryData(); 511 // generate the markup 512 this._generateMarkup(); 513 // set the initial state of the input value and the selected flag 514 this._setInitialState(); 515 // start all of the event listeners: autoHideDialCode, input keydown, selectedFlag click 516 this._initListeners(); 517 // utils script, and auto country 518 this._initRequests(); 519 }, 520 }, 521 { 522 key: "_processCountryData", 523 value: function _processCountryData() { 524 // process onlyCountries or excludeCountries array if present 525 this._processAllCountries(); 526 // process the countryCodes map 527 this._processCountryCodes(); 528 // process the preferredCountries 529 this._processPreferredCountries(); 530 // translate countries according to localizedCountries option 531 if (this.options.localizedCountries) this._translateCountriesByLocale(); 532 // sort countries by name 533 if (this.options.onlyCountries.length || this.options.localizedCountries) { 534 this.countries.sort(this._countryNameSort); 535 } 536 }, 537 }, 538 { 539 key: "_addCountryCode", 540 value: function _addCountryCode(iso2, dialCode, priority) { 541 if (dialCode.length > this.dialCodeMaxLen) { 542 this.dialCodeMaxLen = dialCode.length; 543 } 544 if (!this.countryCodes.hasOwnProperty(dialCode)) { 545 this.countryCodes[dialCode] = []; 546 } 547 // bail if we already have this country for this dialCode 548 for (var i = 0; i < this.countryCodes[dialCode].length; i++) { 549 if (this.countryCodes[dialCode][i] === iso2) return; 550 } 551 // check for undefined as 0 is falsy 552 var index = priority !== undefined ? priority : this.countryCodes[dialCode].length; 553 this.countryCodes[dialCode][index] = iso2; 554 }, 555 }, 556 { 557 key: "_processAllCountries", 558 value: function _processAllCountries() { 559 if (this.options.onlyCountries.length) { 560 var lowerCaseOnlyCountries = this.options.onlyCountries.map(function (country) { 561 return country.toLowerCase(); 562 }); 563 this.countries = allCountries.filter(function (country) { 564 return lowerCaseOnlyCountries.indexOf(country.iso2) > -1; 565 }); 566 } else if (this.options.excludeCountries.length) { 567 var lowerCaseExcludeCountries = this.options.excludeCountries.map(function (country) { 568 return country.toLowerCase(); 569 }); 570 this.countries = allCountries.filter(function (country) { 571 return lowerCaseExcludeCountries.indexOf(country.iso2) === -1; 572 }); 573 } else { 574 this.countries = allCountries; 575 } 576 }, 577 }, 578 { 579 key: "_translateCountriesByLocale", 580 value: function _translateCountriesByLocale() { 581 for (var i = 0; i < this.countries.length; i++) { 582 var iso = this.countries[i].iso2.toLowerCase(); 583 if (this.options.localizedCountries.hasOwnProperty(iso)) { 584 this.countries[i].name = this.options.localizedCountries[iso]; 585 } 586 } 587 }, 588 }, 589 { 590 key: "_countryNameSort", 591 value: function _countryNameSort(a, b) { 592 return a.name.localeCompare(b.name); 593 }, 594 }, 595 { 596 key: "_processCountryCodes", 597 value: function _processCountryCodes() { 598 this.dialCodeMaxLen = 0; 599 this.countryCodes = {}; 600 // first: add dial codes 601 for (var i = 0; i < this.countries.length; i++) { 602 var c = this.countries[i]; 603 this._addCountryCode(c.iso2, c.dialCode, c.priority); 604 } 605 // next: add area codes 606 // this is a second loop over countries, to make sure we have all of the "root" countries 607 // already in the map, so that we can access them, as each time we add an area code substring 608 // to the map, we also need to include the "root" country's code, as that also matches 609 for (var _i = 0; _i < this.countries.length; _i++) { 610 var _c = this.countries[_i]; 611 // area codes 612 if (_c.areaCodes) { 613 var rootCountryCode = this.countryCodes[_c.dialCode][0]; 614 // for each area code 615 for (var j = 0; j < _c.areaCodes.length; j++) { 616 var areaCode = _c.areaCodes[j]; 617 // for each digit in the area code to add all partial matches as well 618 for (var k = 1; k < areaCode.length; k++) { 619 var partialDialCode = _c.dialCode + areaCode.substr(0, k); 620 // start with the root country, as that also matches this dial code 621 this._addCountryCode(rootCountryCode, partialDialCode); 622 this._addCountryCode(_c.iso2, partialDialCode); 623 } 624 // add the full area code 625 this._addCountryCode(_c.iso2, _c.dialCode + areaCode); 626 } 627 } 628 } 629 }, 630 }, 631 { 632 key: "_processPreferredCountries", 633 value: function _processPreferredCountries() { 634 this.preferredCountries = []; 635 for (var i = 0; i < this.options.preferredCountries.length; i++) { 636 var countryCode = this.options.preferredCountries[i].toLowerCase(); 637 var countryData = this._getCountryData(countryCode, false, true); 638 if (countryData) this.preferredCountries.push(countryData); 639 } 640 }, 641 }, 642 { 643 key: "_createEl", 644 value: function _createEl(name, attrs, container) { 645 var el = document.createElement(name); 646 if (attrs)
647 forEachProp(attrs, function (key, value) { 648 return el.setAttribute(key, value); 649 }); 650 if (container) container.appendChild(el); 651 return el; 652 }, 653 }, 654 { 655 key: "_generateMarkup", 656 value: function _generateMarkup() { 657 // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can 658 // easily put the plugin in an inconsistent state e.g. the wrong flag selected for the 659 // autocompleted number, which on submit could mean wrong number is saved (esp in nationalMode) 660 this.telInput.setAttribute("autocomplete", "off"); 661 // containers (mostly for positioning) 662 var parentClass = "iti"; 663 if (this.options.allowDropdown) parentClass += " iti--allow-dropdown"; 664 if (this.options.separateDialCode) parentClass += " iti--separate-dial-code"; 665 if (this.options.customContainer) { 666 parentClass += " "; 667 parentClass += this.options.customContainer; 668 } 669 var wrapper = this._createEl("div", { 670 class: parentClass, 671 }); 672 this.telInput.parentNode.insertBefore(wrapper, this.telInput); 673 this.flagsContainer = this._createEl( 674 "div", 675 { 676 class: "iti__flag-container", 677 }, 678 wrapper 679 ); 680 wrapper.appendChild(this.telInput); 681 // selected flag (displayed to left of input) 682 this.selectedFlag = this._createEl( 683 "div", 684 { 685 class: "iti__selected-flag", 686 role: "combobox", 687 "aria-owns": "country-listbox", 688 }, 689 this.flagsContainer 690 ); 691 this.selectedFlagInner = this._createEl( 692 "div", 693 { 694 class: "iti__flag", 695 }, 696 this.selectedFlag 697 ); 698 if (this.options.separateDialCode) { 699 this.selectedDialCode = this._createEl( 700 "div", 701 { 702 class: "iti__selected-dial-code", 703 }, 704 this.selectedFlag 705 ); 706 } 707 if (this.options.allowDropdown) { 708 // make element focusable and tab navigable 709 this.selectedFlag.setAttribute("tabindex", "0"); 710 this.dropdownArrow = this._createEl( 711 "div", 712 { 713 class: "iti__arrow", 714 }, 715 this.selectedFlag 716 ); 717 // country dropdown: preferred countries, then divider, then all countries 718 this.countryList = this._createEl("ul", { 719 class: "iti__country-list iti__hide", 720 id: "country-listbox", 721 "aria-expanded": "false", 722 role: "listbox", 723 }); 724 if (this.preferredCountries.length) { 725 this._appendListItems(this.preferredCountries, "iti__preferred"); 726 this._createEl( 727 "li", 728 { 729 class: "iti__divider", 730 role: "separator", 731 "aria-disabled": "true", 732 }, 733 this.countryList 734 ); 735 } 736 this._appendListItems(this.countries, "iti__standard"); 737 // create dropdownContainer markup 738 if (this.options.dropdownContainer) { 739 this.dropdown = this._createEl("div", { 740 class: "iti iti--container", 741 }); 742 this.dropdown.appendChild(this.countryList); 743 } else { 744 this.flagsContainer.appendChild(this.countryList); 745 } 746 } 747 if (this.options.hiddenInput) { 748 var hiddenInputName = this.options.hiddenInput; 749 var name = this.telInput.getAttribute("name"); 750 if (name) { 751 var i = name.lastIndexOf("["); 752 // if input name contains square brackets, then give the hidden input the same name, 753 // replacing the contents of the last set of brackets with the given hiddenInput name 754 if (i !== -1) hiddenInputName = "".concat(name.substr(0, i), "[").concat(hiddenInputName, "]"); 755 } 756 this.hiddenInput = this._createEl("input", { 757 type: "hidden", 758 name: hiddenInputName, 759 }); 760 wrapper.appendChild(this.hiddenInput); 761 } 762 }, 763 }, 764 { 765 key: "_appendListItems", 766 value: function _appendListItems(countries, className) { 767 // we create so many DOM elements, it is faster to build a temp string 768 // and then add everything to the DOM in one go at the end 769 var tmp = ""; 770 // for each country 771 for (var i = 0; i < countries.length; i++) { 772 var c = countries[i]; 773 // open the list item 774 tmp += "<li class='iti__country " 775 .concat(className, "' tabIndex='-1' id='iti-item-") 776 .concat(c.iso2, "' role='option' data-dial-code='") 777 .concat(c.dialCode, "' data-country-code='") 778 .concat(c.iso2, "'>"); 779 // add the flag 780 tmp += "<div class='iti__flag-box'><div class='iti__flag iti__".concat(c.iso2, "'></div></div>"); 781 // and the country name and dial code 782 tmp += "<span class='iti__country-name'>
782".concat(c.name, "</span>"); 783 tmp += "<span class='iti__dial-code'>+".concat(c.dialCode, "</span>"); 784 // close the list item 785 tmp += "</li>"; 786 } 787 this.countryList.insertAdjacentHTML("beforeend", tmp); 788 }, 789 }, 790 { 791 key: "_setInitialState", 792 value: function _setInitialState() { 793 var val = this.telInput.value; 794 var dialCode = this._getDialCode(val); 795 var isRegionlessNanp = this._isRegionlessNanp(val); 796 var _this$options = this.options, 797 initialCountry = _this$options.initialCountry, 798 nationalMode = _this$options.nationalMode, 799 autoHideDialCode = _this$options.autoHideDialCode, 800 separateDialCode = _this$options.separateDialCode; 801 // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the 802 // flag, else fall back to the default country 803 if (dialCode && !isRegionlessNanp) { 804 this._updateFlagFromNumber(val); 805 } else if (initialCountry !== "auto") { 806 // see if we should select a flag 807 if (initialCountry) { 808 this._setFlag(initialCountry.toLowerCase()); 809 } else { 810 if (dialCode && isRegionlessNanp) { 811 // has intl dial code, is regionless nanp, and no initialCountry, so default to US 812 this._setFlag("us"); 813 } else { 814 // no dial code and no initialCountry, so default to first in list 815 this.defaultCountry = this.preferredCountries.length 816 ? this.preferredCountries[0].iso2 817 : this.countries[0].iso2; 818 if (!val) { 819 this._setFlag(this.defaultCountry); 820 } 821 } 822 } 823 // if empty and no nationalMode and no autoHideDialCode then insert the default dial code 824 if (!val && !nationalMode && !autoHideDialCode && !separateDialCode) { 825 this.telInput.value = "+".concat(this.selectedCountryData.dialCode); 826 } 827 } 828 // NOTE: if initialCountry is set to auto, that will be handled separately 829 // format - note this wont be run after _updateDialCode as that's only called
829if no val 830 if (val) this._updateValFromNumber(val); 831 }, 832 }, 833 { 834 key: "_initListeners", 835 value: function _initListeners() { 836 this._initKeyListeners(); 837 if (this.options.autoHideDialCode) this._initBlurListeners(); 838 if (this.options.allowDropdown) this._initDropdownListeners(); 839 if (this.hiddenInput) this._initHiddenInputListener(); 840 }, 841 }, 842 { 843 key: "_initHiddenInputListener", 844 value: function _initHiddenInputListener() { 845 var _this3 = this; 846 this._handleHiddenInputSubmit = function () { 847 _this3.hiddenInput.value = _this3.getNumber(); 848 }; 849 if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit); 850 }, 851 }, 852 { 853 key: "_getClosestLabel", 854 value: function _getClosestLabel() { 855 var el = this.telInput; 856 while (el && el.tagName !== "LABEL") { 857 el = el.parentNode; 858 } 859 return el; 860 }, 861 }, 862 { 863 key: "_initDropdownListeners", 864 value: function _initDropdownListeners() { 865 var _this4 = this; 866 // hack for input nested inside label (which is valid markup): clicking the selected-flag to 867 // open the dropdown would then automatically trigger a 2nd click on the input which would 868 // close it again 869 this._handleLabelClick = function (e) { 870 // if the dropdown is closed, then focus the input, else ignore the click 871 if (_this4.countryList.classList.contains("iti__hide")) _this4.telInput.focus(); 872 else e.preventDefault(); 873 }; 874 var label = this._getClosestLabel(); 875 if (label) label.addEventListener("click", this._handleLabelClick); 876 // toggle country dropdown on click 877 this._handleClickSelectedFlag = function () { 878 // only intercept this event if we're opening the dropdown 879 // else let it bubble up to the top ("click-off-to-close" listener) 880 // we cannot just stopPropagation as it may be needed to close another instance 881 if ( 882 _this4.countryList.classList.contains("iti__hide") && 883 !_this4.telInput.disabled && 884 !_this4.telInput.readOnly 885 ) { 886 _this4._showDropdown(); 887 } 888 }; 889 this.selectedFlag.addEventListener("click", this._handleClickSelectedFlag); 890 // open dropdown list if currently focused 891 this._handleFlagsContainerKeydown = function (e) { 892 var isDropdownHidden = _this4.countryList.classList.contains("iti__hide"); 893 if (isDropdownHidden && ["ArrowUp", "ArrowDown", " ", "Enter"].indexOf(e.key) !== -1) { 894 // prevent form from being submitted if "ENTER" was pressed 895 e.preventDefault(); 896 // prevent event from being handled again by document 897 e.stopPropagation(); 898 _this4._showDropdown(); 899 } 900 // allow navigation from dropdown to input on TAB 901 if (e.key === "Tab") _this4._closeDropdown(); 902 }; 903 this.flagsContainer.addEventListener("keydown", this._handleFlagsContainerKeydown); 904 }, 905 }, 906 { 907 key: "_initRequests", 908 value: function _initRequests() { 909 var _this5 = this; 910 // if the user has specified the path to the utils script, fetch it on window.load, else resolve 911 if (this.options.utilsScript && !window.intlTelInputUtils) { 912 // if the plugin is being initialised after the window.load event has already been fired 913 if (window.intlTelInputGlobals.windowLoaded) { 914 window.intlTelInputGlobals.loadUtils(this.options.utilsScript); 915 } else { 916 // wait until the load event so we don't block any other requests e.g. the flags image 917 window.addEventListener("load", function () { 918 window.intlTelInputGlobals.loadUtils(_this5.options.utilsScript); 919 }); 920 } 921 } else this.resolveUtilsScriptPromise(); 922 if (this.options.initialCountry === "auto") this._loadAutoCountry(); 923 else this.resolveAutoCountryPromise(); 924 }, 925 }, 926 { 927 key: "_loadAutoCountry", 928 value: function _loadAutoCountry() { 929 // 3 options: 930 // 1) already loaded (we're done) 931 // 2) not already started loading (start) 932 // 3) already started loading (do nothing - just wait for loading callback to fire) 933 if (window.intlTelInputGlobals.autoCountry) { 934 this.handleAutoCountry(); 935 } else if (!window.intlTelInputGlobals.startedLoadingAutoCountry) { 936 // don't do this twice! 937 window.intlTelInputGlobals.startedLoadingAutoCountry = true; 938 if (typeof this.options.geoIpLookup === "function") { 939 this.options.geoIpLookup( 940 function (countryCode) { 941 window.intlTelInputGlobals.autoCountry = countryCode.toLowerCase(); 942 // tell all instances the auto country is ready 943 // TODO: this should just be the current instances 944 // UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight 945 // away (e.g. if they have already done the geo ip lookup somewhere else). Using 946 // setTimeout means that the current thread of execution will finish before executing 947 // this, which allows the plugin to finish initialising. 948 setTimeout(function () { 949 return forEachInstance("handleAutoCountry"); 950 }); 951 }, 952 function () { 953 return forEachInstance("rejectAutoCountryPromise"); 954 } 955 ); 956 } 957 } 958 }, 959 }, 960 { 961 key: "_initKeyListeners", 962 value: function _initKeyListeners() { 963 var _this6 = this; 964 // update flag on keyup 965 this._handleKeyupEvent = function () { 966 if (_this6._updateFlagFromNumber(_this6.telInput.value)) { 967 _this6._triggerCountryChange(); 968 } 969 }; 970 this.telInput.addEventListener("keyup", this._handleKeyupEvent); 971 // update flag on cut/paste events (now supported in all major browsers) 972 this._handleClipboardEvent = function () { 973 // hack because "paste" event is fired before input is updated 974 setTimeout(_this6._handleKeyupEvent); 975 }; 976 this.telInput.addEventListener("cut", this._handleClipboardEvent); 977 this.telInput.addEventListener("paste", this._handleClipboardEvent); 978 }, 979 }, 980 { 981 key: "_cap", 982 value: function _cap(number) { 983 var max = this.telInput.getAttribute("maxlength"); 984 return max && number.length > max ? number.substr(0, max) : number; 985 }, 986 }, 987 { 988 key: "_initBlurListeners", 989 value: function _initBlurListeners() { 990 var _this7 = this; 991 // on blur or form submit: if just a dial code then remove it 992 this._handleSubmitOrBlurEvent = function () { 993 _this7._removeEmptyDialCode(); 994 }; 995 if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleSubmitOrBlurEvent); 996 this.telInput.addEventListener("blur", this._handleSubmitOrBlurEvent); 997 }, 998 }, 999 { 1000 key: "_removeEmptyDialCode", 1001 value: function _removeEmptyDialCode() { 1002 if (this.telInput.value.charAt(0) === "+") { 1003 var numeric = this._getNumeric(this.telInput.value); 1004 // if just a plus, or if just a dial code 1005 if (!numeric || this.selectedCountryData.dialCode === numeric) { 1006 this.telInput.value = ""; 1007 } 1008 } 1009 }, 1010 }, 1011 { 1012 key: "_getNumeric", 1013 value: function _getNumeric(s) { 1014 return s.replace(/\D/g, ""); 1015 }, 1016 }, 1017 { 1018 key: "_trigger", 1019 value: function _trigger(name) {
1020 // have to use old school document.createEvent as IE11 doesn't support `new Event()` syntax 1021 var e = document.createEvent("Event"); 1022 e.initEvent(name, true, true); 1023 // can bubble, and is cancellable 1024 this.telInput.dispatchEvent(e); 1025 }, 1026 }, 1027 { 1028 key: "_showDropdown", 1029 value: function _showDropdown() { 1030 this.countryList.classList.remove("iti__hide"); 1031 this.countryList.setAttribute("aria-expanded", "true"); 1032 this._setDropdownPosition(); 1033 // update highlighting and scroll to active list item 1034 if (this.activeItem) { 1035 this._highlightListItem(this.activeItem, false); 1036 this._scrollTo(this.activeItem, true); 1037 } 1038 // bind all the dropdown-related listeners: mouseover, click, click-off, keydown 1039 this._bindDropdownListeners(); 1040 // update the arrow 1041 this.dropdownArrow.classList.add("iti__arrow--up"); 1042 this._trigger("open:countrydropdown"); 1043 }, 1044 }, 1045 { 1046 key: "_toggleClass", 1047 value: function _toggleClass(el, className, shouldHaveClass) { 1048 if (shouldHaveClass && !el.classList.contains(className)) el.classList.add(className); 1049 else if (!shouldHaveClass && el.classList.contains(className)) el.classList.remove(className); 1050 }, 1051 }, 1052 { 1053 key: "_setDropdownPosition", 1054 value: function _setDropdownPosition() { 1055 var _this8 = this; 1056 if (this.options.dropdownContainer) { 1057 this.options.dropdownContainer.appendChild(this.dropdown); 1058 } 1059 if (!this.isMobile) { 1060 var pos = this.telInput.getBoundingClientRect(); 1061 // windowTop from https://stackoverflow.com/a/14384091/217866 1062 var windowTop = window.pageYOffset || document.documentElement.scrollTop; 1063 var inputTop = pos.top + windowTop; 1064 var dropdownHeight = this.countryList.offsetHeight; 1065 // dropdownFitsBelow = (dropdownBottom < windowBottom) 1066 var dropdownFitsBelow = 1067 inputTop + this.telInput.offsetHeight + dropdownHeight < windowTop + window.innerHeight; 1068 var dropdownFitsAbove = inputTop - dropdownHeight > windowTop; 1069 // by default, the dropdown will be below the input. If we want to position it above the 1070 // input, we add the dropup class. 1071 this._toggleClass( 1072 this.countryList, 1073 "iti__country-list--dropup", 1074 !dropdownFitsBelow && dropdownFitsAbove 1075 ); 1076 // if dropdownContainer is enabled, calculate postion 1077 if (this.options.dropdownContainer) { 1078 // by default the dropdown will be directly over the input because it's not in the flow. 1079 // If we want to position it below, we need to add some extra top value. 1080 var extraTop = !dropdownFitsBelow && dropdownFitsAbove ? 0 : this.telInput.offsetHeight; 1081 // calculate placement 1082 this.dropdown.style.top = "".concat(inputTop + extraTop, "px"); 1083 this.dropdown.style.left = "".concat(pos.left + document.body.scrollLeft, "px"); 1084 // close menu on window scroll 1085 this._handleWindowScroll = function () { 1086 return _this8._closeDropdown(); 1087 }; 1088 window.addEventListener("scroll", this._handleWindowScroll); 1089 } 1090 } 1091 }, 1092 }, 1093 { 1094 key: "_getClosestListItem", 1095 value: function _getClosestListItem(target) { 1096 var el = target; 1097 while (el && el !== this.countryList && !el.classList.contains("iti__country")) { 1098 el = el.parentNode; 1099 } 1100 // if we reached the countryList element, then return null 1101 return el === this.countryList ? null : el; 1102 }, 1103 }, 1104 { 1105 key: "_bindDropdownListeners", 1106 value: function _bindDropdownListeners() { 1107 var _this9 = this; 1108 // when mouse over a list item, just highlight that one 1109 // we add the class "highlight", so if they hit "enter" we know
1109which one to select 1110 this._handleMouseoverCountryList = function (e) { 1111 // handle event delegation, as we're listening for this event on the countryList 1112 var listItem = _this9._getClosestListItem(e.target); 1113 if (listItem) _this9._highlightListItem(listItem, false); 1114 }; 1115 this.countryList.addEventListener("mouseover", this._handleMouseoverCountryList); 1116 // listen for country selection 1117 this._handleClickCountryList = function (e) { 1118 var listItem = _this9._getClosestListItem(e.target); 1119 if (listItem) _this9._selectListItem(listItem); 1120 }; 1121 this.countryList.addEventListener("click", this._handleClickCountryList); 1122 // click off to close 1123 // (except when this initial opening click is bubbling up) 1124 // we cannot just stopPropagation as it may be needed to close another instance 1125 var isOpening = true; 1126 this._handleClickOffToClose = function () { 1127 if (!isOpening) _this9._closeDropdown(); 1128 isOpening = false; 1129 }; 1130 document.documentElement.addEventListener("click", this._handleClickOffToClose); 1131 // listen for up/down scrolling, enter to select, or letters to jump to country name. 1132 // use keydown as keypress doesn't fire for non-char keys and we want to catch if they 1133 // just hit down and hold it to scroll down (no keyup event). 1134 // listen on the document because that's where key events are triggered if no input has focus 1135 var query = ""; 1136 var queryTimer = null; 1137 this._handleKeydownOnDropdown = function (e) { 1138 // prevent down key from scrolling the whole page, 1139 // and enter key from submitting a form etc 1140 e.preventDefault(); 1141 // up and down to navigate 1142 if (e.key === "ArrowUp" || e.key === "ArrowDown") _this9._handleUpDownKey(e.key); 1143 else if (e.key === "Enter") _this9._handleEnterKey(); 1144 else if (e.key === "Escape") _this9._closeDropdown(); 1145 else if (/^[a-zA-ZÃ-ÿ ]$/.test(e.key)) { 1146 // jump to countries that start with the query string 1147 if (queryTimer) clearTimeout(queryTimer); 1148 query += e.key.toLowerCase(); 1149 _this9._searchForCountry(query); 1150 // if the timer hits 1 second, reset the query 1151 queryTimer = setTimeout(function () { 1152 query = ""; 1153 }, 1e3); 1154 } 1155 }; 1156 document.addEventListener("keydown", this._handleKeydownOnDropdown); 1157 }, 1158 }, 1159 { 1160 key: "_handleUpDownKey", 1161 value: function _handleUpDownKey(key) { 1162 var next = 1163 key === "ArrowUp" 1164 ? this.highlightedItem.previousElementSibling 1165 : this.highlightedItem.nextElementSibling; 1166 if (next) { 1167 // skip the divider 1168 if (next.classList.contains("iti__divider")) { 1169 next = key === "ArrowUp" ? next.previousElementSibling : next.nextElementSibling; 1170 } 1171 this._highlightListItem(next, true); 1172 } 1173 }, 1174 }, 1175 { 1176 key: "_handleEnterKey", 1177 value: function _handleEnterKey() { 1178 if (this.highlightedItem) this._selectListItem(this.highlightedItem); 1179 }, 1180 }, 1181 { 1182 key: "_searchForCountry", 1183 value: function _searchForCountry(query) { 1184 for (var i = 0; i < this.countries.length; i++) { 1185 if (this._startsWith(this.countries[i].name, query)) { 1186 var listItem = this.countryList.querySelector("#iti-item-".concat(this.countries[i].iso2)); 1187 // update highlighting and scroll 1188 this._highlightListItem(listItem, false); 1189 this._scrollTo(listItem, true); 1190 break; 1191 } 1192 } 1193 }, 1194 }, 1195 { 1196 key: "_startsWith", 1197 value: function _startsWith(a, b) { 1198 return a.substr(0, b.length).toLowerCase() === b; 1199 }, 1200 }, 1201 {
1202 key: "_updateValFromNumber", 1203 value: function _updateValFromNumber(originalNumber) { 1204 var number = originalNumber; 1205 if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) { 1206 var useNational = 1207 !this.options.separateDialCode && (this.options.nationalMode || number.charAt(0) !== "+"); 1208 var _intlTelInputUtils$nu = intlTelInputUtils.numberFormat, 1209 NATIONAL = _intlTelInputUtils$nu.NATIONAL, 1210 INTERNATIONAL = _intlTelInputUtils$nu.INTERNATIONAL; 1211 var format = useNational ? NATIONAL : INTERNATIONAL; 1212 number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format); 1213 } 1214 number = this._beforeSetNumber(number); 1215 this.telInput.value = number; 1216 }, 1217 }, 1218 { 1219 key: "_updateFlagFromNumber", 1220 value: function _updateFlagFromNumber(originalNumber) { 1221 // if we're in nationalMode and we already have US/Canada selected, make sure the number starts 1222 // with a +1 so _getDialCode will be able to extract the area code 1223 // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag 1224 // from the number), that means we're initialising the plugin with a number that already has a 1225 // dial code, so fine to ignore this bit 1226 var number = originalNumber; 1227 var selectedDialCode = this.selectedCountryData.dialCode; 1228 var isNanp = selectedDialCode === "1"; 1229 if (number && this.options.nationalMode && isNanp && number.charAt(0) !== "+") { 1230 if (number.charAt(0) !== "1") number = "1".concat(number); 1231 number = "+".concat(number); 1232 } 1233 // update flag if user types area code for another country 1234 if (this.options.separateDialCode && selectedDialCode && number.charAt(0) !== "+") { 1235 number = "+".concat(selectedDialCode).concat(number); 1236 } 1237 // try and extract valid dial code from input 1238 var dialCode = this._getDialCode(number); 1239 var numeric = this._getNumeric(number); 1240 var countryCode = null; 1241 if (dialCode) { 1242 var countryCodes = this.countryCodes[this._getNumeric(dialCode)]; 1243 // check if the right country is already selected. this should be false if the number is 1244 // longer than the matched dial code because in this case we need to make sure that if 1245 // there are multiple country matches, that the first one is selected (note: we could 1246 // just check that here, but it requires the same loop that we already have later) 1247 var alreadySelected = 1248 countryCodes.indexOf(this.selectedCountryData.iso2) !== -1 && numeric.length <= dialCode.length - 1; 1249 var isRegionlessNanpNumber = selectedDialCode === "1" && this._isRegionlessNanp(numeric); 1250 // only update the flag if: 1251 // A) NOT (we currently have a NANP flag selected, and the number is a regionlessNanp) 1252 // AND 1253 // B) the right country is not already selected 1254 if (!isRegionlessNanpNumber && !alreadySelected) { 1255 // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first 1256 // non-empty index 1257 for (var j = 0; j < countryCodes.length; j++) { 1258 if (countryCodes[j]) { 1259 countryCode = countryCodes[j]; 1260 break; 1261 } 1262 } 1263 } 1264 } else if (number.charAt(0) === "+" && numeric.length) { 1265 // invalid dial code, so empty 1266 // Note: use getNumeric here because the number has not been formatted yet, so could contain 1267 // bad chars 1268 countryCode = ""; 1269 } else if (!number || number === "+") { 1270 // empty, or just a plus, so default 1271 countryCode = this.defaultCountry; 1272 } 1273 if (countryCode !== null) { 1274 return this._setFlag(countryCode); 1275 } 1276 return false;
1277 }, 1278 }, 1279 { 1280 key: "_isRegionlessNanp", 1281 value: function _isRegionlessNanp(number) { 1282 var numeric = this._getNumeric(number); 1283 if (numeric.charAt(0) === "1") { 1284 var areaCode = numeric.substr(1, 3); 1285 return regionlessNanpNumbers.indexOf(areaCode) !== -1; 1286 } 1287 return false; 1288 }, 1289 }, 1290 { 1291 key: "_highlightListItem", 1292 value: function _highlightListItem(listItem, shouldFocus) { 1293 var prevItem = this.highlightedItem; 1294 if (prevItem) prevItem.classList.remove("iti__highlight"); 1295 this.highlightedItem = listItem; 1296 this.highlightedItem.classList.add("iti__highlight"); 1297 if (shouldFocus) this.highlightedItem.focus(); 1298 }, 1299 }, 1300 { 1301 key: "_getCountryData", 1302 value: function _getCountryData(countryCode, ignoreOnlyCountriesOption, allowFail) { 1303 var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries; 1304 for (var i = 0; i < countryList.length; i++) { 1305 if (countryList[i].iso2 === countryCode) { 1306 return countryList[i]; 1307 } 1308 } 1309 if (allowFail) { 1310 return null; 1311 } 1312 throw new Error("No country data for '".concat(countryCode, "'")); 1313 }, 1314 }, 1315 { 1316 key: "_setFlag", 1317 value: function _setFlag(countryCode) { 1318 var prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {}; 1319 // do this first as it will throw an error and stop if countryCode is invalid 1320 this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {}; 1321 // update the defaultCountry - we only need the iso2 from now on, so just store that 1322 if (this.selectedCountryData.iso2) { 1323 this.defaultCountry = this.selectedCountryData.iso2; 1324 } 1325 this.selectedFlagInner.setAttribute("class", "iti__flag iti__".concat(countryCode)); 1326 // update the selected country's title attribute 1327 var title = countryCode 1328 ? "".concat(this.selectedCountryData.name, ": +").concat(this.selectedCountryData.dialCode) 1329 : "Unknown"; 1330 this.selectedFlag.setAttribute("title", title); 1331 if (this.options.separateDialCode) { 1332 var dialCode = this.selectedCountryData.dialCode ? "+".concat(this.selectedCountryData.dialCode) : ""; 1333 this.selectedDialCode.innerHTML = dialCode; 1334 // offsetWidth is zero if input is in a hidden container during initialisation 1335 var selectedFlagWidth = this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth(); 1336 // add 6px of padding after the grey selected-dial-code box, as this is what we use in the css 1337 this.telInput.style.paddingLeft = "".concat(selectedFlagWidth + 6, "px"); 1338 } 1339 // and the input's placeholder 1340 this._updatePlaceholder(); 1341 // update the active list item 1342 if (this.options.allowDropdown) { 1343 var prevItem = this.activeItem; 1344 if (prevItem) { 1345 prevItem.classList.remove("iti__active"); 1346 prevItem.setAttribute("aria-selected", "false"); 1347 } 1348 if (countryCode) { 1349 var nextItem = this.countryList.querySelector("#iti-item-".concat(countryCode)); 1350 nextItem.setAttribute("aria-selected", "true"); 1351 nextItem.classList.add("iti__active"); 1352 this.activeItem = nextItem; 1353 this.countryList.setAttribute("aria-activedescendant", nextItem.getAttribute("id")); 1354 } 1355 } 1356 // return if the flag has changed or not 1357 return prevCountry.iso2 !== countryCode; 1358 }, 1359 }, 1360 { 1361 key: "_getHiddenSelectedFlagWidth", 1362 value: function _getHiddenSelectedFlagWidth() { 1363 // to get the right styling to apply, all we need is a shallow clone of the container, 1364 // and then to inject a deep clone of the selectedFlag element 1365 var containerClone = this.telInput.parentNode.cloneNode(); 1366 containerClone.style.visibility = "hidden"; 1367 document.body.appendChild(containerClone); 1368 var selectedFlagClone = this.selectedFlag.cloneNode(true); 1369 containerClone.appendChild(selectedFlagClone); 1370 var width = selectedFlagClone.offsetWidth; 1371 containerClone.remove(); 1372 return width; 1373 }, 1374 }, 1375 { 1376 key: "_updatePlaceholder", 1377 value: function _updatePlaceholder() { 1378 var shouldSetPlaceholder = 1379 this.options.autoPlaceholder === "aggressive" || 1380 (!this.hadInitialPlaceholder && this.options.autoPlaceholder === "polite"); 1381 if (window.intlTelInputUtils && shouldSetPlaceholder) { 1382 var numberType = intlTelInputUtils.numberType[this.options.placeholderNumberType]; 1383 var placeholder = this.selectedCountryData.iso2 1384 ? intlTelInputUtils.getExampleNumber( 1385 this.selectedCountryData.iso2, 1386 this.options.nationalMode, 1387 numberType 1388 ) 1389 : ""; 1390 placeholder = this._beforeSetNumber(placeholder); 1391 if (typeof this.options.customPlaceholder === "function") { 1392 placeholder = this.options.customPlaceholder(placeholder, this.selectedCountryData); 1393 } 1394 this.telInput.setAttribute("placeholder", placeholder); 1395 } 1396 }, 1397 }, 1398 { 1399 key: "_selectListItem", 1400 value: function _selectListItem(listItem) { 1401 // update selected flag and active list item 1402 var flagChanged = this._setFlag(listItem.getAttribute("data-country-code")); 1403 this._closeDropdown(); 1404 this._updateDialCode(listItem.getAttribute("data-dial-code"), true); 1405 // focus the input 1406 this.telInput.focus(); 1407 // put cursor at end - this fix is required for FF and IE11 (with nationalMode=false i.e. auto 1408 // inserting dial code), who try to put the cursor at the beginning the first time 1409 var len = this.telInput.value.length; 1410 this.telInput.setSelectionRange(len, len); 1411 if (flagChanged) { 1412 this._triggerCountryChange(); 1413 } 1414 }, 1415 }, 1416 { 1417 key: "_closeDropdown", 1418 value: function _closeDropdown() { 1419 this.countryList.classList.add("iti__hide"); 1420 this.countryList.setAttribute("aria-expanded", "false"); 1421 // update the arrow 1422 this.dropdownArrow.classList.remove("iti__arrow--up"); 1423 // unbind key events 1424 document.removeEventListener("keydown", this._handleKeydownOnDropdown); 1425 document.documentElement.removeEventListener("click", this._handleClickOffToClose); 1426 this.countryList.removeEventListener("mouseover", this._handleMouseoverCountryList); 1427 this.countryList.removeEventListener("click", this._handleClickCountryList); 1428 // remove menu from container 1429 if (this.options.dropdownContainer) { 1430 if (!this.isMobile) window.removeEventListener("scroll", this._handleWindowScroll); 1431 if (this.dropdown.parentNode) this.dropdown.parentNode.removeChild(this.dropdown); 1432 } 1433 this._trigger("close:countrydropdown"); 1434 }, 1435 }, 1436 { 1437 key: "_scrollTo", 1438 value: function _scrollTo(element, middle) { 1439 var container = this.countryList; 1440 // windowTop from https://stackoverflow.com/a/14384091/2
144017866 1441 var windowTop = window.pageYOffset || document.documentElement.scrollTop; 1442 var containerHeight = container.offsetHeight; 1443 var containerTop = container.getBoundingClientRect().top + windowTop; 1444 var containerBottom = containerTop + containerHeight; 1445 var elementHeight = element.offsetHeight; 1446 var elementTop = element.getBoundingClientRect().top + windowTop; 1447 var elementBottom = elementTop + elementHeight; 1448 var newScrollTop = elementTop - containerTop + container.scrollTop; 1449 var middleOffset = containerHeight / 2 - elementHeight / 2; 1450 if (elementTop < containerTop) { 1451 // scroll up 1452 if (middle) newScrollTop -= middleOffset; 1453 container.scrollTop = newScrollTop; 1454 } else if (elementBottom > containerBottom) { 1455 // scroll down 1456 if (middle) newScrollTop += middleOffset; 1457 var heightDifference = containerHeight - elementHeight; 1458 container.scrollTop = newScrollTop - heightDifference; 1459 } 1460 }, 1461 }, 1462 { 1463 key: "_updateDialCode", 1464 value: function _updateDialCode(newDialCodeBare, hasSelectedListItem) { 1465 var inputVal = this.telInput.value; 1466 // save having to pass this every time 1467 var newDialCode = "+".concat(newDialCodeBare); 1468 var newNumber; 1469 if (inputVal.charAt(0) === "+") { 1470 // there's a plus so we're dealing with a replacement (doesn't matter if nationalMode or not) 1471 var prevDialCode = this._getDialCode(inputVal); 1472 if (prevDialCode) { 1473 // current number contains a valid dial code, so replace it 1474 newNumber = inputVal.replace(prevDialCode, newDialCode); 1475 } else { 1476 // current number contains an invalid dial code, so ditch it 1477 // (no way to determine where the invalid dial code ends and the rest of the number begins) 1478 newNumber = newDialCode; 1479 } 1480 } else if (this.options.nationalMode || this.options.separateDialCode) { 1481 // don't do anything 1482 return; 1483 } else { 1484 // nationalMode is disabled 1485 if (inputVal) { 1486 // there is an existing value with no dial code: prefix the new dial code 1487 newNumber = newDialCode + inputVal; 1488 } else if (hasSelectedListItem || !this.options.autoHideDialCode) { 1489 // no existing value and either they've just selected a list item, or autoHideDialCode is 1490 // disabled: insert new dial code 1491 newNumber = newDialCode; 1492 } else { 1493 return; 1494 } 1495 } 1496 this.telInput.value = newNumber; 1497 }, 1498 }, 1499 { 1500 key: "_getDialCode", 1501 value: function _getDialCode(number) { 1502 var dialCode = ""; 1503 // only interested in international numbers (starting with a plus) 1504 if (number.charAt(0) === "+") { 1505 var numericChars = ""; 1506 // iterate over chars 1507 for (var i = 0; i < number.length; i++) { 1508 var c = number.charAt(i); 1509 // if char is number (https://stackoverflow.com/a/8935649/217866) 1510 if (!isNaN(parseInt(c, 10))) { 1511 numericChars += c; 1512 // if current numericChars make a valid dial code 1513 if (this.countryCodes[numericChars]) { 1514 // store the actual raw string (useful for matching later) 1515 dialCode = number.substr(0, i + 1); 1516 } 1517 if (numericChars.length === this.dialCodeMaxLen) { 1518 break; 1519 } 1520 } 1521 } 1522 } 1523 return dialCode; 1524 }, 1525 }, 1526 { 1527 key: "_getFullNumber", 1528 value: function _getFullNumber() { 1529 var val = this.telInput.value.trim(); 1530 var dialCode = this.selectedCountryData.dialCode; 1531 var prefix; 1532 var numericVal = this._getNumeric(val); 1533 if (this.options.separateDialCode && val.charAt(0) !== "+" && dialCode && numericVal) { 1534 // when using separateDialCode, it is visible so is effectively part of the typed number 1535 prefix = "+".concat(dialCode); 1536 } else { 1537 prefix = ""; 1538 } 1539 return prefix + val; 1540 }, 1541 }, 1542 { 1543 key: "_beforeSetNumber", 1544 value: function _beforeSetNumber(originalNumber) { 1545 var number = originalNumber; 1546 if (this.options.separateDialCode) { 1547 var dialCode = this._getDialCode(number); 1548 // if there is a valid dial code 1549 if (dialCode) { 1550 // in case _getDialCode returned an area code as well 1551 dialCode = "+".concat(this.selectedCountryData.dialCode); 1552 // a lot of numbers will have a space separating the dial code and the main number, and 1553 // some NANP numbers will have a hyphen e.g. +1 684-733-1234 - in both cases we want to get 1554 // rid of it 1555 // NOTE: don't just trim all non-numerics as may want to preserve an open parenthesis etc 1556 var start = 1557 number[dialCode.length] === " " || number[dialCode.length] === "-" 1558 ? dialCode.length + 1 1559 : dialCode.length; 1560 number = number.substr(start); 1561 } 1562 } 1563 return this._cap(number); 1564 }, 1565 }, 1566 { 1567 key: "_triggerCountryChange", 1568 value: function _triggerCountryChange() { 1569 this._trigger("countrychange"); 1570 }, 1571 }, 1572 { 1573 key: "handleAutoCountry", 1574 value: function handleAutoCountry() { 1575 if (this.options.initialCountry === "auto") { 1576 // we must set this even if there is an initial val in the input: in case the initial val is 1577 // invalid and they delete it - they should see their auto country 1578 this.defaultCountry = window.intlTelInputGlobals.autoCountry; 1579 // if there's no initial value in the input, then update the flag 1580 if (!this.telInput.value) { 1581 this.setCountry(this.defaultCountry); 1582 } 1583 this.resolveAutoCountryPromise(); 1584 } 1585 }, 1586 }, 1587 { 1588 key: "handleUtils", 1589 value: function handleUtils() { 1590 // if the request was successful 1591 if (window.intlTelInputUtils) { 1592 // if there's an initial value in the input, then format it 1593 if (this.telInput.value) {
1594 this._updateValFromNumber(this.telInput.value); 1595 } 1596 this._updatePlaceholder(); 1597 } 1598 this.resolveUtilsScriptPromise(); 1599 }, 1600 }, 1601 { 1602 key: "destroy", 1603 value: function destroy() { 1604 var form = this.telInput.form; 1605 if (this.options.allowDropdown) { 1606 // make sure the dropdown is closed (and unbind listeners) 1607 this._closeDropdown(); 1608 this.selectedFlag.removeEventListener("click", this._handleClickSelectedFlag); 1609 this.flagsContainer.removeEventListener("keydown", this._handleFlagsContainerKeydown); 1610 // label click hack 1611 var label = this._getClosestLabel(); 1612 if (label) label.removeEventListener("click", this._handleLabelClick); 1613 } 1614 // unbind hiddenInput listeners 1615 if (this.hiddenInput && form) form.removeEventListener("submit", this._handleHiddenInputSubmit); 1616 // unbind autoHideDialCode listeners 1617 if (this.options.autoHideDialCode) { 1618 if (form) form.removeEventListener("submit", this._handleSubmitOrBlurEvent); 1619 this.telInput.removeEventListener("blur", this._handleSubmitOrBlurEvent); 1620 } 1621 // unbind key events, and cut/paste events 1622 this.telInput.removeEventListener("keyup", this._handleKeyupEvent); 1623 this.telInput.removeEventListener("cut", this._handleClipboardEvent); 1624 this.telInput.removeEventListener("paste", this._handleClipboardEvent); 1625 // remove attribute of id instance: data-intl-tel-input-id 1626 this.telInput.removeAttribute("data-intl-tel-input-id"); 1627 // remove markup (but leave the original input) 1628 var wrapper = this.telInput.parentNode; 1629 wrapper.parentNode.insertBefore(this.telInput, wrapper); 1630 wrapper.parentNode.removeChild(wrapper); 1631 delete window.intlTelInputGlobals.instances[this.id]; 1632 }, 1633 }, 1634 { 1635 key: "getExtension", 1636 value: function getExtension() { 1637 if (window.intlTelInputUtils) { 1638 return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2); 1639 } 1640 return ""; 1641 }, 1642 }, 1643 { 1644 key: "getNumber", 1645 value: function getNumber(format) { 1646 if (window.intlTelInputUtils) { 1647 var iso2 = this.selectedCountryData.iso2; 1648 return intlTelInputUtils.formatNumber(this._getFullNumber(), iso2, format); 1649 } 1650 return ""; 1651 }, 1652 }, 1653 { 1654 key: "getNumberType", 1655 value: function getNumberType() { 1656 if (window.intlTelInputUtils) { 1657 return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2); 1658 } 1659 return -99; 1660 }, 1661 }, 1662 { 1663 key: "getSelectedCountryData", 1664 value: function getSelectedCountryData() { 1665 return this.selectedCountryData; 1666 }, 1667 }, 1668 { 1669 key: "getValidationError", 1670 value: function getValidationError() { 1671 if (window.intlTelInputUtils) { 1672 var iso2 = this.selectedCountryData.iso2; 1673 return intlTelInputUtils.getValidationError(this._getFullNumber(), iso2); 1674 } 1675 return -99; 1676 }, 1677 }, 1678 { 1679 key: "isValidNumber", 1680 value: function isValidNumber() { 1681 var val = this._getFullNumber().trim(); 1682 var countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : ""; 1683 return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null; 1684 }, 1685 }, 1686 { 1687 key: "setCountry", 1688 value: function setCountry(originalCountryCode) { 1689 var countryCode = originalCountryCode.toLowerCase(); 1690 // check if already selected 1691 if (!this.selectedFlagInner.classList.contains("iti__".concat(countryCode))) { 1692 this._setFlag(countryCode); 1693 this._updateDialCode(this.selectedCountryData.dialCode, false); 1694 this._triggerCountryChange(); 1695 } 1696 }, 1697 }, 1698 { 1699 key: "setNumber", 1700 value: function setNumber(number) { 1701 // we must update the flag first, which updates this.selectedCountryData, which is used for 1702 // formatting the number before displaying it 1703 var flagChanged = this._updateFlagFromNumber(number);
1704 this._updateValFromNumber(number); 1705 if (flagChanged) { 1706 this._triggerCountryChange(); 1707 } 1708 }, 1709 }, 1710 { 1711 key: "setPlaceholderNumberType", 1712 value: function setPlaceholderNumberType(type) { 1713 this.options.placeholderNumberType = type; 1714 this._updatePlaceholder(); 1715 }, 1716 }, 1717 ]); 1718 return Iti; 1719 })(); 1720 /******************** 1721 * STATIC METHODS 1722 ********************/ 1723 // get the country data object 1724 window.intlTelInputGlobals.getCountryData = function () { 1725 return allCountries; 1726 }; 1727 // inject a <script> element to load utils.js 1728 var injectScript = function injectScript(path, handleSuccess, handleFailure) { 1729 // inject a new script element into the page 1730 var script = document.createElement("script"); 1731 script.onload = function () { 1732 forEachInstance("handleUtils"); 1733 if (handleSuccess) handleSuccess(); 1734 }; 1735 script.onerror = function () { 1736 forEachInstance("rejectUtilsScriptPromise"); 1737 if (handleFailure) handleFailure(); 1738 }; 1739 script.className = "iti-load-utils"; 1740 script.async = true; 1741 script.src = path; 1742 document.body.appendChild(script); 1743 }; 1744 // load the utils script 1745 window.intlTelInputGlobals.loadUtils = function (path) { 1746 // 2 options: 1747 // 1) not already started loading (start) 1748 // 2) already started loading (do nothing - just wait for the onload callback to fire, which will 1749 // trigger handleUtils on all instances, invoking their resolveUtilsScriptPromise functions) 1750 if (!window.intlTelInputUtils && !window.intlTelInputGlobals.startedLoadingUtilsScript) { 1751 // only do this once 1752 window.intlTelInputGlobals.startedLoadingUtilsScript = true; 1753 // if we have promises, then return a promise 1754 if (typeof Promise !== "undefined") { 1755 return new Promise(function (resolve, reject) { 1756 return injectScript(path, resolve, reject); 1757 }); 1758 } 1759 injectScript(path); 1760 } 1761 return null; 1762 }; 1763 // default options 1764 window.intlTelInputGlobals.defaults = defaults; 1765 // version 1766 window.intlTelInputGlobals.version = "16.0.0"; 1767 // convenience wrapper 1768 return function (input, options) { 1769 var iti = new Iti(input, options); 1770 iti._init(); 1771 input.setAttribute("data-intl-tel-input-id", iti.id); 1772 window.intlTelInputGlobals.instances[iti.id] = iti; 1773 return iti; 1774 }; 1775 })(); 1776});
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.