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