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