1/* 2 * International Telephone Input v17.0.8 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) { 10 module.exports = factory(require("jquery")); 11 } else if (typeof define === "function" && define.amd) { 12 define( 13 [ "jquery" ], function ($) { 14 factory($); 15 } 16 ); 17 } else { factory(jQuery); 18 } 19})( 20 function ($, undefined) { 21 "use strict"; 22 // Array of country objects for the flag dropdown. 23 // Here is the criteria for the plugin to support a given country/territory 24 // - It has an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 25 // - 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 26 // - It has a flag in the region-flags project: https://github.com/behdad/region-flags/tree/gh-pages/png 27 // - It is supported by libphonenumber (it must be listed on this page): https://github.com/googlei18n/libphonenumber/blob/master/resources/ShortNumberMetadata.xml 28 // Each country array has the following information: 29 // [ 30 // Country name, 31 // iso2 code, 32 // International dial code, 33 // Order (if >1 country with same dial code), 34 // Area codes 35 // ] 36 var allCountries = [ [ "Afghanistan (â«Ø§ÙØºØ§ÙØ³ØªØ§Ùâ¬â)", "af", "93" ], [ "Albania (Shqipëri)", "al", "355" ], [ "Algeria (â«Ø§Ùجزائرâ¬â)", "dz", "213" ], [ "Andorra", "ad", "376" ], [ "Angola", "ao", "244" ], [ "Argentina", "ar", "54" ], [ "Armenia (ÕÕ¡ÕµÕ¡Õ½Õ¿Õ¡Õ¶)", "am", "374" ], [ "Aruba", "aw", "297" ], [ "Australia", "au", "61", 0 ], [ "Austria (Ãsterreich)", "at", "43" ], [ "Azerbaijan (AzÉrbaycan)", "az", "994" ], [ "Bahrain (â«Ø§ÙØ¨ØØ±ÙÙâ¬â)", "bh", "973" ], [ "Bangladesh (বাà¦à¦²à¦¾à¦¦à§à¦¶)", "bd", "880" ], [ "Belarus (ÐелаÑÑÑÑ)", "by", "375" ], [ "Belgium (België)", "be", "32" ], [ "Belize", "bz", "501" ], [ "Benin (Bénin)", "bj", "229" ], [ "Bhutan (འà½à¾²à½´à½)", "bt", "975" ], [ "Bolivia", "bo", "591" ], [ "Bosnia and Herzegovina (ÐоÑна и ХеÑÑеговина)", "ba", "387" ], [ "Botswana", "bw", "267" ], [ "Brazil (Brasil)", "br", "55" ], [ "British Indian Ocean Territory", "io", "246" ], [ "Brunei", "bn", "673" ], [ "Bulgaria (ÐÑлгаÑиÑ)", "bg", "359" ], [ "Burkina Faso", "bf", "226" ], [ "Burundi (Uburundi)", "bi", "257" ], [ "Cambodia (ááááá»áá¶)", "kh", "855" ], [ "Cameroon (Cameroun)", "cm", "237" ], [ "Cape Verde (Kabu Verdi)", "cv", "238" ], [ "Caribbean Netherlands", "bq", "599", 1, [ "3", "4", "7" ] ], [ "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" ], [ "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
36aat)", "gl", "299" ], [ "Guadeloupe", "gp", "590", 0 ], [ "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 ], [ "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" ], [ "Macedonia (FYROM) (ÐакедониÑа)", "mk", "389" ], [ "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" ], [ "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" ], [ "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" ], [ "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 Martin (Saint-Martin (partie française))", "mf", "590", 2 ], [ "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)", "pm", "508" ], [ "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" ], [ "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" ], [ "Tunisia (â«ØªÙÙØ³â¬â)", "tn", "216" ], [ "Turkey (Türkiye)", "tr", "90" ], [ "Turkmenistan", "tm", "993" ], [ "Tuvalu", "tv", "688" ], [ "Uganda", "ug", "256" ], [ "Ukraine (УкÑаÑна)", "ua", "380" ], [ "United Arab Emirates (â«Ø§Ùإ٠ارات Ø§ÙØ¹Ø±Ø¨ÙØ© اÙÙ ØªØØ¯Ø©â¬â)", "ae", "971" ], [ "United Kingdom", "gb", "44", 0 ], [ "United States", "us", "1", 0 ], [ "Uruguay", "uy", "598" ], [ "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" ] ] ]; 37 // loop over all of the countries above, restructuring the data to be objects with named keys 38 for (var i = 0; i < allCountries.length; i++) { 39 var c = allCountries[i]; 40 allCountries[i] = { 41 name: c[0], 42 iso2: c[1], 43 dialCode: c[2], 44 priority: c[3] || 0, 45 areaCodes: c[4] || null 46 }; 47 } 48 "use strict"; 49 function _classCallCheck(instance, Constructor) 50 { 51 if (!(instance instanceof Constructor)) { 52 throw new TypeError("Cannot call a class as a function"); 53 } 54 } 55 function _defineProperties(target, props) 56 { 57 for (var i = 0; i < props.length; i++) { 58 var descriptor = props[i]; 59 descriptor.enumerable = descriptor.enumerable || false; 60 descriptor.configurable = true; 61 if ("value" in descriptor) { descriptor.writable = true; 62 } 63 Object.defineProperty(target, descriptor.key, descriptor); 64 } 65 } 66 function _createClass(Constructor, protoProps, staticProps) 67 { 68 if (protoProps) { _defineProperties(Constructor.prototype, protoProps); 69 } 70 if (staticProps) { _defineProperties(Constructor, staticProps); 71 } 72 return Constructor; 73 } 74 var intlTelInputGlobals = { 75 getInstance: function getInstance(input) 76 { 77 var id = input.getAttribute("data-intl-tel-input-id"); 78 return window.intlTelInputGlobals.instances[id]; 79 }, 80 instances: {}, 81 // using a global like this allows us to mock it in the tests 82 documentReady: function documentReady() 83 { 84 return document.readyState === "complete"; 85 } 86 }; 87 if (typeof window === "object") { window.intlTelInputGlobals = intlTelInputGlobals; 88 } 89 // these vars persist through all instances of the plugin 90 var id = 0; 91 var defaults = { 92 // whether or not to allow the dropdown 93 allowDropdown: true, 94 // whether or not to show country flag 95 showFlags: true, 96 // if there is just a dial code in the input: remove it on blur 97 autoHideDialCode: true, 98 // add a placeholder in the input with an example number for the selected country 99 autoPlaceholder: "polite", 100 // modify the parentClass 101 customContainer: "", 102 // modify the auto placeholder 103 customPlaceholder: null, 104 // append menu to specified element 105 dropdownContainer: null, 106 // don't display these countries 107 excludeCountries: [], 108 // format the input value during initialisation and on setNumber 109 formatOnDisplay: true, 110 // geoIp lookup function 111 geoIpLookup: null, 112 // inject a hidden input with this name, and on submit, populate it with the result of getNumber 113 hiddenInput: "", 114 // initial country 115 initialCountry: "", 116 // localized country names e.g. { 'de': 'Deutschland' } 117 localizedCountries: null, 118 // don't insert international dial codes 119 nationalMode: true, 120 // display only these countries 121 onlyCountries: [], 122 // number type to use for placeholders 123 placeholderNumberType: "MOBILE", 124 // the countries at the top of the list. defaults to united states and united kingdom 125 preferredCountries: [ "us", "gb" ], 126 // display the country dial code next to the selected flag so it's not part of the typed number 127 separateDialCode: false, 128 // specify the path to the libphonenumber script to enable validation/formatting 129 utilsScript: "" 130 }; 131 // https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#Non-geographic_area_codes 132 var regionlessNanpNumbers = [ "800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889" ]; 133 // utility function to iterate over an object. can't use Object.entries or native forEac
vendor: 13,855 bytes, lines 133-379
133h because 134 // of IE11 135 var forEachProp = function forEachProp(obj, callback) 136 { 137 var keys = Object.keys(obj); 138 for (var i = 0; i < keys.length; i++) { 139 callback(keys[i], obj[keys[i]]); 140 } 141 }; 142 // run a method on each instance of the plugin 143 var forEachInstance = function forEachInstance(method) 144 { 145 forEachProp( 146 window.intlTelInputGlobals.instances, function (key) { 147 window.intlTelInputGlobals.instances[key][method](); 148 } 149 ); 150 }; 151 // this is our plugin class that we will create an instance of 152 // eslint-disable-next-line no-unused-vars 153 var Iti = /*#__PURE__*/ 154 function () { 155 function Iti(input, options) 156 { 157 var _this = this; 158 _classCallCheck(this, Iti); 159 this.id = id++; 160 this.telInput = input; 161 this.activeItem = null; 162 this.highlightedItem = null; 163 // process specified options / defaults 164 // alternative to Object.assign, which isn't supported by IE11 165 var customOptions = options || {}; 166 this.options = {}; 167 forEachProp( 168 defaults, function (key, value) { 169 _this.options[key] = customOptions.hasOwnProperty(key) ? customOptions[key] : value; 170 } 171 ); 172 this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder")); 173 } 174 _createClass( 175 Iti, [ { 176 key: "_init", 177 value: function _init() 178 { 179 var _this2 = this; 180 // if in nationalMode, disable options relating to dial codes 181 if (this.options.nationalMode) { this.options.autoHideDialCode = false; 182 } 183 // if separateDialCode then doesn't make sense to A) insert dial code into input 184 // (autoHideDialCode), and B) display national numbers (because we're displaying the country 185 // dial code next to them) 186 if (this.options.separateDialCode) { 187 this.options.autoHideDialCode = this.options.nationalMode = false; 188 } 189 // we cannot just test screen size as some smartphones/website meta tags will report desktop 190 // resolutions 191 // Note: for some reason jasmine breaks if you put this in the main Plugin function with the 192 // rest of these declarations 193 // Note: to target Android Mobiles (and not Tablets), we must find 'Android' and 'Mobile' 194 this.isMobile = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); 195 if (this.isMobile) { 196 // trigger the mobile dropdown css 197 document.body.classList.add("iti-mobile"); 198 // on mobile, we want a full screen dropdown, so we must append it to the body 199 if (!this.options.dropdownContainer) { this.options.dropdownContainer = document.body; 200 } 201 } 202 // these promises get resolved when their individual requests complete 203 // this way the dev can do something like iti.promise.then(...) to know when all requests are 204 // complete 205 if (typeof Promise !== "undefined") { 206 var autoCountryPromise = new Promise( 207 function (resolve, reject) { 208 _this2.resolveAutoCountryPromise = resolve; 209 _this2.rejectAutoCountryPromise = reject; 210 } 211 ); 212 var utilsScriptPromise = new Promise( 213 function (resolve, reject) { 214 _this2.resolveUtilsScriptPromise = resolve; 215 _this2.rejectUtilsScriptPromise = reject; 216 } 217 ); 218 this.promise = Promise.all([ autoCountryPromise, utilsScriptPromise ]); 219 } else { 220 // prevent errors when Promise doesn't exist 221 this.resolveAutoCountryPromise = this.rejectAutoCountryPromise = function () {}; 222 this.resolveUtilsScriptPromise = this.rejectUtilsScriptPromise = function () {}; 223 } 224 // in various situations there could be no country selected initially, but we need to be able 225 // to assume this variable exists 226 this.selectedCountryData = {}; 227 // process all the data: onlyCountries, excludeCountries, preferredCountries etc 228 this._processCountryData(); 229 // generate the markup 230 this._generateMarkup(); 231 // set the initial state of the input value and the selected flag 232 this._setInitialState(); 233 // start all of the event listeners: autoHideDialCode, input keydown, selectedFlag click 234 this._initListeners(); 235 // utils script, and auto country 236 this._initRequests(); 237 } 238 }, { 239 key: "_processCountryData", 240 value: function _processCountryData() 241 { 242 // process onlyCountries or excludeCountries array if present 243 this._processAllCountries(); 244 // process the countryCodes map 245 this._processCountryCodes(); 246 // process the preferredCountries 247 this._processPreferredCountries(); 248 // translate countries according to localizedCountries option 249 if (this.options.localizedCountries) { this._translateCountriesByLocale(); 250 } 251 // sort countries by name 252 if (this.options.onlyCountries.length || this.options.localizedCountries) { 253 this.countries.sort(this._countryNameSort); 254 } 255 } 256 }, { 257 key: "_addCountryCode", 258 value: function _addCountryCode(iso2, countryCode, priority) 259 { 260 if (countryCode.length > this.countryCodeMaxLen) { 261 this.countryCodeMaxLen = countryCode.length; 262 } 263 if (!this.countryCodes.hasOwnProperty(countryCode)) { 264 this.countryCodes[countryCode] = []; 265 } 266 // bail if we already have this country for this countryCode 267 for (var i = 0; i < this.countryCodes[countryCode].length; i++) { 268 if (this.countryCodes[countryCode][i] === iso2) { return; 269 } 270 } 271 // check for undefined as 0 is falsy 272 var index = priority !== undefined ? priority : this.countryCodes[countryCode].length; 273 this.countryCodes[countryCode][index] = iso2; 274 } 275 }, { 276 key: "_processAllCountries", 277 value: function _processAllCountries() 278 { 279 if (this.options.onlyCountries.length) { 280 var lowerCaseOnlyCountries = this.options.onlyCountries.map( 281 function (country) { 282 return country.toLowerCase(); 283 } 284 ); 285 this.countries = allCountries.filter( 286 function (country) { 287 return lowerCaseOnlyCountries.indexOf(country.iso2) > -1; 288 } 289 ); 290 } else if (this.options.excludeCountries.length) { 291 var lowerCaseExcludeCountries = this.options.excludeCountries.map( 292 function (country) { 293 return country.toLowerCase(); 294 } 295 ); 296 this.countries = allCountries.filter( 297 function (country) { 298 return lowerCaseExcludeCountries.indexOf(country.iso2) === -1; 299 } 300 ); 301 } else { 302 this.countries = allCountries; 303 } 304 } 305 }, { 306 key: "_translateCountriesByLocale", 307 value: function _translateCountriesByLocale() 308 { 309 for (var i = 0; i < this.countries.length; i++) { 310 var iso = this.countries[i].iso2.toLowerCase(); 311 if (this.options.localizedCountries.hasOwnProperty(iso)) { 312 this.countries[i].name = this.options.localizedCountries[iso]; 313 } 314 } 315 } 316 }, { 317 key: "_countryNameSort", 318 value: function _countryNameSort(a, b) 319 { 320 return a.name.localeCompare(b.name); 321 } 322 }, { 323 key: "_processCountryCodes", 324 value: function _processCountryCodes() 325 { 326 this.countryCodeMaxLen = 0; 327 // here we store just dial codes 328 this.dialCodes = {}; 329 // here we store "country codes" (both dial codes and their area codes) 330 this.countryCodes = {}; 331 // first: add dial codes 332 for (var i = 0; i < this.countries.length; i++) { 333 var c = this.countries[i]; 334 if (!this.dialCodes[c.dialCode]) { this.dialCodes[c.dialCode] = true; 335 } 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 { 367 this.preferredCountries = []; 368 for (var i = 0; i < this.options.preferredCountries.length; i++) { 369 var countryCode = this.options.preferredCountries[i].toLowerCase(); 370 var countryData = this._getCountryData(countryCode, false, true); 371 if (countryData) { this.preferredCountries.push(countryData); 372 } 373 } 374 } 375 }, { 376 key: "_createEl", 377 value: function _createEl(name, attrs, container) 378 { 379 var el = document.createElement(name);
380 if (attrs) { forEachProp( 381 attrs, function (key, value) { 382 return el.setAttribute(key, value); 383 } 384 ); 385 } 386 if (container) { container.appendChild(el); 387 } 388 return el; 389 } 390 }, { 391 key: "_generateMarkup", 392 value: function _generateMarkup() 393 { 394 // if autocomplete does not exist on the element and its form, then 395 // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can 396 // easily put the plugin in an inconsistent state e.g. the wrong flag selected for the 397 // autocompleted number, which on submit could mean wrong number is saved (esp in nationalMode) 398 if (!this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete"))) { 399 this.telInput.setAttribute("autocomplete", "off"); 400 } 401 402 // containers (mostly for positioning) 403 var parentClass = "iti"; 404 if (this.options.allowDropdown) { parentClass += " iti--allow-dropdown"; 405 } 406 if (this.options.separateDialCode) { parentClass += " iti--separate-dial-code"; 407 } 408 if (this.options.customContainer) { 409 parentClass += " "; 410 parentClass += this.options.customContainer; 411 } 412 var wrapper = this._createEl( 413 "div", { 414 "class": parentClass 415 } 416 ); 417 this.telInput.parentNode.insertBefore(wrapper, this.telInput); 418 jQuery(this.telInput.form).find('.iti__flag-container').remove(); 419 this.flagsContainer = this._createEl( 420 "div", { 421 "class": "iti__flag-container" 422 }, wrapper 423 ); 424 wrapper.appendChild(this.telInput); 425 // selected flag (displayed to left of input) 426 this.selectedFlag = this._createEl( 427 "div", { 428 "class": "iti__selected-flag", 429 role: "combobox", 430 "aria-controls": "iti-".concat(this.id, "__country-listbox"), 431 "aria-owns": "iti-".concat(this.id, "__country-listbox"), 432 "aria-expanded": "false" 433 }, this.flagsContainer 434 ); 435 if (this.options.showFlags) { 436 this.selectedFlagInner = this._createEl( 437 "div", { 438 "class": "iti__flag" 439 }, this.selectedFlag 440 ); 441 } 442 if (this.options.separateDialCode) { 443 this.selectedDialCode = this._createEl( 444 "div", { 445 "class": "iti__selected-dial-code" 446 }, this.selectedFlag 447 ); 448 } 449 if (this.options.allowDropdown) { 450 // make element focusable and tab navigable 451 this.selectedFlag.setAttribute("tabindex", "0"); 452 this.dropdownArrow = this._createEl( 453 "div", { 454 "class": "iti__arrow" 455 }, this.selectedFlag 456 ); 457 // country dropdown: preferred countries, then divider, then all countries 458 this.countryList = this._createEl( 459 "ul", { 460 "class": "iti__country-list iti__hide", 461 id: "iti-".concat(this.id, "__country-listbox"), 462 role: "listbox", 463 "aria-label": "List of countries" 464 } 465 ); 466 if (this.preferredCountries.length) { 467 this._appendListItems(this.preferredCountries, "iti__preferred", true); 468 this._createEl( 469 "li", { 470 "class": "iti__divider", 471 role: "separator", 472 "aria-disabled": "true" 473 }, this.countryList 474 ); 475 } 476 this._appendListItems(this.countries, "iti__standard"); 477 // create dropdownContainer markup 478 if (this.options.dropdownContainer) { 479 this.dropdown = this._createEl( 480 "div", { 481 "class": "iti iti--container" 482 } 483 ); 484 this.dropdown.appendChild(this.countryList); 485 } else { 486 this.flagsContainer.appendChild(this.countryList); 487 } 488 } 489 if (this.options.hiddenInput) { 490 var hiddenInputName = this.options.hiddenInput; 491 var name = this.telInput.getAttribute("name"); 492 if (name) { 493 var i = name.lastIndexOf("["); 494 // if input name contains square brackets, then give the hidden input the same name, 495 // replacing the contents of the last set of brackets with the given hiddenInput name 496 if (i !== -1) { hiddenInputName = "".concat(name.substr(0, i), "[").concat(hiddenInputName, "]"); 497 } 498 } 499 this.hiddenInput = this._createEl( 500 "input", { 501 type: "hidden", 502 name: hiddenInputName 503 } 504 ); 505 wrapper.appendChild(this.hiddenInput); 506 } 507 } 508 }, { 509 key: "_appendListItems", 510 value: function _appendListItems(countries, className, preferred) 511 { 512 // we create so many DOM elements, it is faster to build a temp string 513 // and then add everything to the DOM in one go at the end 514 var tmp = ""; 515 // for each country 516 for (var i = 0; i < countries.length; i++) { 517 var c = countries[i]; 518 var idSuffix = preferred ? "-preferred" : ""; 519 // open the list item 520 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'>"); 521 // add the flag 522 if (this.options.showFlags) { 523 tmp += "<div class='iti__flag-box'><div class='iti__flag iti__".concat(c.iso2, "'></div></div>"); 524 } 525 // and the country name and dial code 526 tmp += "<span class='iti__country-name'>
vendor: 30,421 bytes, lines 526-1015
526".concat(c.name, "</span>"); 527 tmp += "<span class='iti__dial-code'>+".concat(c.dialCode, "</span>"); 528 // close the list item 529 tmp += "</li>"; 530 } 531 this.countryList.insertAdjacentHTML("beforeend", tmp); 532 } 533 }, { 534 key: "_setInitialState", 535 value: function _setInitialState() 536 { 537 var val = this.telInput.value; 538 var dialCode = this._getDialCode(val); 539 var isRegionlessNanp = this._isRegionlessNanp(val); 540 var _this$options = this.options, initialCountry = _this$options.initialCountry, nationalMode = _this$options.nationalMode, autoHideDialCode = _this$options.autoHideDialCode, separateDialCode = _this$options.separateDialCode; 541 // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the 542 // flag, else fall back to the default country 543 if (dialCode && !isRegionlessNanp) { 544 this._updateFlagFromNumber(val); 545 } else if (initialCountry !== "auto") { 546 // see if we should select a flag 547 if (initialCountry) { 548 this._setFlag(initialCountry.toLowerCase()); 549 } else { 550 if (dialCode && isRegionlessNanp) { 551 // has intl dial code, is regionless nanp, and no initialCountry, so default to US 552 this._setFlag("us"); 553 } else { 554 // no dial code and no initialCountry, so default to first in list 555 this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2; 556 if (!val) { 557 this._setFlag(this.defaultCountry); 558 } 559 } 560 } 561 // if empty and no nationalMode and no autoHideDialCode then insert the default dial code 562 if (!val && !nationalMode && !autoHideDialCode && !separateDialCode) { 563 this.telInput.value = "+".concat(this.selectedCountryData.dialCode); 564 } 565 } 566 // NOTE: if initialCountry is set to auto, that will be handled separately 567 // format - note this wont be run after _updateDialCode as that's only called if no val 568 if (val) { this._updateValFromNumber(val); 569 } 570 } 571 }, { 572 key: "_initListeners", 573 value: function _initListeners() 574 { 575 this._initKeyListeners(); 576 if (this.options.autoHideDialCode) { this._initBlurListeners(); 577 } 578 if (this.options.allowDropdown) { this._initDropdownListeners(); 579 } 580 if (this.hiddenInput) { this._initHiddenInputListener(); 581 } 582 } 583 }, { 584 key: "_initHiddenInputListener", 585 value: function _initHiddenInputListener() 586 { 587 var _this3 = this; 588 this._handleHiddenInputSubmit = function () { 589 _this3.hiddenInput.value = _this3.getNumber(); 590 }; 591 if (this.telInput.form) { this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit); 592 } 593 } 594 }, { 595 key: "_getClosestLabel", 596 value: function _getClosestLabel() 597 { 598 var el = this.telInput; 599 while (el && el.tagName !== "LABEL") { 600 el = el.parentNode; 601 } 602 return el; 603 } 604 }, { 605 key: "_initDropdownListeners", 606 value: function _initDropdownListeners() 607 { 608 var _this4 = this; 609 // hack for input nested inside label (which is valid markup): clicking the selected-flag to 610 // open the dropdown would then automatically trigger a 2nd click on the input which would 611 // close it again 612 this._handleLabelClick = function (e) { 613 // if the dropdown is closed, then focus the input, else ignore the click 614 if (_this4.countryList.classList.contains("iti__hide")) { _this4.telInput.focus(); } else { e.preventDefault(); 615 } 616 }; 617 var label = this._getClosestLabel(); 618 if (label) { label.addEventListener("click", this._handleLabelClick); 619 } 620 // toggle country dropdown on click 621 this._handleClickSelectedFlag = function () { 622 // only intercept this event if we're opening the dropdown 623 // else let it bubble up to the top ("click-off-to-close" listener) 624 // we cannot just stopPropagation as it may be needed to close another instance 625 if (_this4.countryList.classList.contains("iti__hide") && !_this4.telInput.disabled && !_this4.telInput.readOnly) { 626 _this4._showDropdown(); 627 } 628 }; 629 this.selectedFlag.addEventListener("click", this._handleClickSelectedFlag); 630 // open dropdown list if currently focused 631 this._handleFlagsContainerKeydown = function (e) { 632 var isDropdownHidden = _this4.countryList.classList.contains("iti__hide"); 633 if (isDropdownHidden && [ "ArrowUp", "Up", "ArrowDown", "Down", " ", "Enter" ].indexOf(e.key) !== -1) { 634 // prevent form from being submitted if "ENTER" was pressed 635 e.preventDefault(); 636 // prevent event from being handled again by document 637 e.stopPropagation(); 638 _this4._showDropdown(); 639 } 640 // allow navigation from dropdown to input on TAB 641 if (e.key === "Tab") { _this4._closeDropdown(); 642 } 643 }; 644 this.flagsContainer.addEventListener("keydown", this._handleFlagsContainerKeydown); 645 } 646 }, { 647 key: "_initRequests", 648 value: function _initRequests() 649 { 650 var _this5 = this; 651 // if the user has specified the path to the utils script, fetch it on window.load, else resolve 652 if (this.options.utilsScript && !window.intlTelInputUtils) { 653 // if the plugin is being initialised after the window.load event has already been fired 654 if (window.intlTelInputGlobals.documentReady()) { 655 window.intlTelInputGlobals.loadUtils(this.options.utilsScript); 656 } else { 657 // wait until the load event so we don't block any other requests e.g. the flags image 658 window.addEventListener( 659 "load", function () { 660 window.intlTelInputGlobals.loadUtils(_this5.options.utilsScript); 661 } 662 ); 663 } 664 } else { this.resolveUtilsScriptPromise(); 665 } 666 if (this.options.initialCountry === "auto") { this._loadAutoCountry(); } else { this.resolveAutoCountryPromise(); 667 } 668 } 669 }, { 670 key: "_loadAutoCountry", 671 value: function _loadAutoCountry() 672 { 673 // 3 options: 674 // 1) already loaded (we're done) 675 // 2) not already started loading (start) 676 // 3) already started loading (do nothing - just wait for loading callback to fire) 677 if (window.intlTelInputGlobals.autoCountry) { 678 this.handleAutoCountry(); 679 } else if (!window.intlTelInputGlobals.startedLoadingAutoCountry) { 680 // don't do this twice! 681 window.intlTelInputGlobals.startedLoadingAutoCountry = true; 682 if (typeof this.options.geoIpLookup === "function") { 683 this.options.geoIpLookup( 684 function (countryCode) { 685 window.intlTelInputGlobals.autoCountry = countryCode.toLowerCase(); 686 // tell all instances the auto country is ready 687 // TODO: this should just be the current instances 688 // UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight 689 // away (e.g. if they have already done the geo ip lookup somewhere else). Using 690 // setTimeout means that the current thread of execution will finish before executing 691 // this, which allows the plugin to finish initialising. 692 setTimeout( 693 function () { 694 return forEachInstance("handleAutoCountry"); 695 } 696 ); 697 }, function () { 698 return forEachInstance("rejectAutoCountryPromise"); 699 } 700 ); 701 } 702 } 703 } 704 }, { 705 key: "_initKeyListeners", 706 value: function _initKeyListeners() 707 { 708 var _this6 = this; 709 // update flag on keyup 710 this._handleKeyupEvent = function () { 711 if (_this6._updateFlagFromNumber(_this6.telInput.value)) { 712 _this6._triggerCountryChange(); 713 } 714 }; 715 this.telInput.addEventListener("keyup", this._handleKeyupEvent); 716 // update flag on cut/paste events (now supported in all major browsers) 717 this._handleClipboardEvent = function () { 718 // hack because "paste" event is fired before input is updated 719 setTimeout(_this6._handleKeyupEvent); 720 }; 721 this.telInput.addEventListener("cut", this._handleClipboardEvent); 722 this.telInput.addEventListener("paste", this._handleClipboardEvent); 723 } 724 }, { 725 key: "_cap", 726 value: function _cap(number) 727 { 728 var max = this.telInput.getAttribute("maxlength"); 729 return max && number.length > max ? number.substr(0, max) : number; 730 } 731 }, { 732 key: "_initBlurListeners", 733 value: function _initBlurListeners() 734 { 735 var _this7 = this; 736 // on blur or form submit: if just a dial code then remove it 737 this._handleSubmitOrBlurEvent = function () { 738 _this7._removeEmptyDialCode(); 739 }; 740 if (this.telInput.form) { this.telInput.form.addEventListener("submit", this._handleSubmitOrBlurEvent); 741 } 742 this.telInput.addEventListener("blur", this._handleSubmitOrBlurEvent); 743 } 744 }, { 745 key: "_removeEmptyDialCode", 746 value: function _removeEmptyDialCode() 747 { 748 if (this.telInput.value.charAt(0) === "+") { 749 var numeric = this._getNumeric(this.telInput.value); 750 // if just a plus, or if just a dial code 751 if (!numeric || this.selectedCountryData.dialCode === numeric) { 752 this.telInput.value = ""; 753 } 754 } 755 } 756 }, { 757 key: "_getNumeric", 758 value: function _getNumeric(s) 759 { 760 return s.replace(/\D/g, ""); 761 } 762 }, { 763 key: "_trigger", 764 value: function _trigger(name) 765 { 766 // have to use old school document.createEvent as IE11 doesn't support `new Event()` syntax 767 var e = document.createEvent("Event"); 768 e.initEvent(name, true, true); 769 // can bubble, and is cancellable 770 this.telInput.dispatchEvent(e); 771 } 772 }, { 773 key: "_showDropdown", 774 value: function _showDropdown() 775 { 776 this.countryList.classList.remove("iti__hide"); 777 this.selectedFlag.setAttribute("aria-expanded", "true"); 778 this._setDropdownPosition(); 779 // update highlighting and scroll to active list item 780 if (this.activeItem) { 781 this._highlightListItem(this.activeItem, false); 782 this._scrollTo(this.activeItem, true); 783 } 784 // bind all the dropdown-related listeners: mouseover, click, click-off, keydown 785 this._bindDropdownListeners(); 786 // update the arrow 787 this.dropdownArrow.classList.add("iti__arrow--up"); 788 this._trigger("open:countrydropdown"); 789 } 790 }, { 791 key: "_toggleClass", 792 value: function _toggleClass(el, className, shouldHaveClass) 793 { 794 if (shouldHaveClass && !el.classList.contains(className)) { el.classList.add(className); } else if (!shouldHaveClass && el.classList.contains(className)) { el.classList.remove(className); 795 } 796 } 797 }, { 798 key: "_setDropdownPosition", 799 value: function _setDropdownPosition() 800 { 801 var _this8 = this; 802 if (this.options.dropdownContainer) { 803 this.options.dropdownContainer.appendChild(this.dropdown); 804 } 805 if (!this.isMobile) { 806 var pos = this.telInput.getBoundingClientRect(); 807 // windowTop from https://stackoverflow.com/a/14384091/217866 808 var windowTop = window.pageYOffset || document.documentElement.scrollTop; 809 var inputTop = pos.top + windowTop; 810 var dropdownHeight = this.countryList.offsetHeight; 811 // dropdownFitsBelow = (dropdownBottom < windowBottom) 812 var dropdownFitsBelow = inputTop + this.telInput.offsetHeight + dropdownHeight < windowTop + window.innerHeight; 813 var dropdownFitsAbove = inputTop - dropdownHeight > windowTop; 814 // by default, the dropdown will be below the input. If we want to position it above the 815 // input, we add the dropup class. 816 this._toggleClass(this.countryList, "iti__country-list--dropup", !dropdownFitsBelow && dropdownFitsAbove); 817 // if dropdownContainer is enabled, calculate postion 818 if (this.options.dropdownContainer) { 819 // by default the dropdown will be directly over the input because it's not in the flow. 820 // If we want to position it below, we need to add some extra top value. 821 var extraTop = !dropdownFitsBelow && dropdownFitsAbove ? 0 : this.telInput.offsetHeight; 822 // calculate placement 823 this.dropdown.style.top = "".concat(inputTop + extraTop, "px"); 824 this.dropdown.style.left = "".concat(pos.left + document.body.scrollLeft, "px"); 825 // close menu on window scroll 826 this._handleWindowScroll = function () { 827 return _this8._closeDropdown(); 828 }; 829 window.addEventListener("scroll", this._handleWindowScroll); 830 } 831 } 832 } 833 }, { 834 key: "_getClosestListItem", 835 value: function _getClosestListItem(target) 836 { 837 var el = target; 838 while (el && el !== this.countryList && !el.classList.contains("iti__country")) { 839 el = el.parentNode; 840 } 841 // if we reached the countryList element, then return null 842 return el === this.countryList ? null : el; 843 } 844 }, { 845 key: "_bindDropdownListeners", 846 value: function _bindDropdownListeners() 847 { 848 var _this9 = this; 849 // when mouse over a list item, just highlight that one 850 // we add the class "highlight", so if they hit "enter" we know which one to select 851 this._handleMouseoverCountryList = function (e) { 852 // handle event delegation, as we're listening for this event on the countryList 853 var listItem = _this9._getClosestListItem(e.target); 854 if (listItem) { _this9._highlightListItem(listItem, false); 855 } 856 }; 857 this.countryList.addEventListener("mouseover", this._handleMouseoverCountryList); 858 // listen for country selection 859 this._handleClickCountryList = function (e) { 860 var listItem = _this9._getClosestListItem(e.target); 861 if (listItem) { _this9._selectListItem(listItem); 862 } 863 }; 864 this.countryList.addEventListener("click", this._handleClickCountryList); 865 // click off to close 866 // (except when this initial opening click is bubbling up) 867 // we cannot just stopPropagation as it may be needed to close another instance 868 var isOpening = true; 869 this._handleClickOffToClose = function () { 870 if (!isOpening) { _this9._closeDropdown(); 871 } 872 isOpening = false; 873 }; 874 document.documentElement.addEventListener("click", this._handleClickOffToClose); 875 // listen for up/down scrolling, enter to select, or letters to jump to country name. 876 // use keydown as keypress doesn't fire for non-char keys and we want to catch if they 877 // just hit down and hold it to scroll down (no keyup event). 878 // listen on the document because that's where key events are triggered if no input has focus 879 var query = ""; 880 var queryTimer = null; 881 this._handleKeydownOnDropdown = function (e) { 882 // prevent down key from scrolling the whole page, 883 // and enter key from submitting a form etc 884 e.preventDefault(); 885 // up and down to navigate 886 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)) { 887 // jump to countries that start with the query string 888 if (queryTimer) { clearTimeout(queryTimer); 889 } 890 query += e.key.toLowerCase(); 891 _this9._searchForCountry(query); 892 // if the timer hits 1 second, reset the query 893 queryTimer = setTimeout( 894 function () { 895 query = ""; 896 }, 1e3 897 ); 898 } 899 }; 900 document.addEventListener("keydown", this._handleKeydownOnDropdown); 901 } 902 }, { 903 key: "_handleUpDownKey", 904 value: function _handleUpDownKey(key) 905 { 906 var next = key === "ArrowUp" || key === "Up" ? this.highlightedItem.previousElementSibling : this.highlightedItem.nextElementSibling; 907 if (next) { 908 // skip the divider 909 if (next.classList.contains("iti__divider")) { 910 next = key === "ArrowUp" || key === "Up" ? next.previousElementSibling : next.nextElementSibling; 911 } 912 this._highlightListItem(next, true); 913 } 914 } 915 }, { 916 key: "_handleEnterKey", 917 value: function _handleEnterKey() 918 { 919 if (this.highlightedItem) { this._selectListItem(this.highlightedItem); 920 } 921 } 922 }, { 923 key: "_searchForCountry", 924 value: function _searchForCountry(query) 925 { 926 for (var i = 0; i < this.countries.length; i++) { 927 if (this._startsWith(this.countries[i].name, query)) { 928 var listItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(this.countries[i].iso2)); 929 // update highlighting and scroll 930 this._highlightListItem(listItem, false); 931 this._scrollTo(listItem, true); 932 break; 933 } 934 } 935 } 936 }, { 937 key: "_startsWith", 938 value: function _startsWith(a, b) 939 { 940 return a.substr(0, b.length).toLowerCase() === b; 941 } 942 }, { 943 key: "_updateValFromNumber", 944 value: function _updateValFromNumber(originalNumber) 945 { 946 var number = originalNumber; 947 if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) { 948 var useNational = !this.options.separateDialCode && (this.options.nationalMode || number.charAt(0) !== "+"); 949 var _intlTelInputUtils$nu = intlTelInputUtils.numberFormat, NATIONAL = _intlTelInputUtils$nu.NATIONAL, INTERNATIONAL = _intlTelInputUtils$nu.INTERNATIONAL; 950 var format = useNational ? NATIONAL : INTERNATIONAL; 951 number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format); 952 } 953 number = this._beforeSetNumber(number); 954 this.telInput.value = number; 955 } 956 }, { 957 key: "_updateFlagFromNumber", 958 value: function _updateFlagFromNumber(originalNumber) 959 { 960 // if we're in nationalMode and we already have US/Canada selected, make sure the number starts 961 // with a +1 so _getDialCode will be able to extract the area code 962 // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag 963 // from the number), that means we're initialising the plugin with a number that already has a 964 // dial code, so fine to ignore this bit 965 var number = originalNumber; 966 var selectedDialCode = this.selectedCountryData.dialCode; 967 var isNanp = selectedDialCode === "1"; 968 if (number && this.options.nationalMode && isNanp && number.charAt(0) !== "+") { 969 if (number.charAt(0) !== "1") { number = "1".concat(number); 970 } 971 number = "+".concat(number); 972 } 973 // update flag if user types area code for another country 974 if (this.options.separateDialCode && selectedDialCode && number.charAt(0) !== "+") { 975 number = "+".concat(selectedDialCode).concat(number); 976 } 977 // try and extract valid dial code from input 978 var dialCode = this._getDialCode(number, true); 979 var numeric = this._getNumeric(number); 980 var countryCode = null; 981 if (dialCode) { 982 var countryCodes = this.countryCodes[this._getNumeric(dialCode)]; 983 // check if the right country is already selected. this should be false if the number is 984 // longer than the matched dial code because in this case we need to make sure that if 985 // there are multiple country matches, that the first one is selected (note: we could 986 // just check that here, but it requires the same loop that we already have later) 987 var alreadySelected = countryCodes.indexOf(this.selectedCountryData.iso2) !== -1 && numeric.length <= dialCode.length - 1; 988 var isRegionlessNanpNumber = selectedDialCode === "1" && this._isRegionlessNanp(numeric); 989 // only update the flag if: 990 // A) NOT (we currently have a NANP flag selected, and the number is a regionlessNanp) 991 // AND 992 // B) the right country is not already selected 993 if (!isRegionlessNanpNumber && !alreadySelected) { 994 // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first 995 // non-empty index 996 for (var j = 0; j < countryCodes.length; j++) { 997 if (countryCodes[j]) { 998 countryCode = countryCodes[j]; 999 break; 1000 } 1001 } 1002 } 1003 } else if (number.charAt(0) === "+" && numeric.length) { 1004 // invalid dial code, so empty 1005 // Note: use getNumeric here because the number has not been formatted yet, so could contain 1006 // bad chars 1007 countryCode = ""; 1008 } else if (!number || number === "+") { 1009 // empty, or just a plus, so default 1010 countryCode = this.defaultCountry; 1011 } 1012 if (countryCode !== null) { 1013 return this._setFlag(countryCode); 1014 } 1015 return false;
1016 } 1017 }, { 1018 key: "_isRegionlessNanp", 1019 value: function _isRegionlessNanp(number) 1020 { 1021 var numeric = this._getNumeric(number); 1022 if (numeric.charAt(0) === "1") { 1023 var areaCode = numeric.substr(1, 3); 1024 return regionlessNanpNumbers.indexOf(areaCode) !== -1; 1025 } 1026 return false; 1027 } 1028 }, { 1029 key: "_highlightListItem", 1030 value: function _highlightListItem(listItem, shouldFocus) 1031 { 1032 var prevItem = this.highlightedItem; 1033 if (prevItem) { prevItem.classList.remove("iti__highlight"); 1034 } 1035 this.highlightedItem = listItem; 1036 this.highlightedItem.classList.add("iti__highlight"); 1037 if (shouldFocus) { this.highlightedItem.focus(); 1038 } 1039 } 1040 }, { 1041 key: "_getCountryData", 1042 value: function _getCountryData(countryCode, ignoreOnlyCountriesOption, allowFail) 1043 { 1044 var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries; 1045 for (var i = 0; i < countryList.length; i++) { 1046 if (countryList[i].iso2 === countryCode) { 1047 return countryList[i]; 1048 } 1049 } 1050 if (allowFail) { 1051 return null; 1052 } 1053 throw new Error("No country data for '".concat(countryCode, "'")); 1054 } 1055 }, { 1056 key: "_setFlag", 1057 value: function _setFlag(countryCode) 1058 { 1059 var prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {}; 1060 // do this first as it will throw an error and stop if countryCode is invalid 1061 try{ 1062 this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {}; 1063 // update the defaultCountry - we only need the iso2 from now on, so just store that 1064 if (this.selectedCountryData.iso2) { 1065 this.defaultCountry = this.selectedCountryData.iso2; 1066 } 1067 if (this.options.showFlags) { 1068 this.selectedFlagInner.setAttribute("class", "iti__flag iti__".concat(countryCode)); 1069 } 1070 // update the selected country's title attribute 1071 var title = countryCode ? "".concat(this.selectedCountryData.name, ": +").concat(this.selectedCountryData.dialCode) : "Unknown"; 1072 this.selectedFlag.setAttribute("title", title); 1073 } 1074 catch(err){} 1075 if (this.options.separateDialCode) { 1076 var dialCode = this.selectedCountryData.dialCode ? "+".concat(this.selectedCountryData.dialCode) : ""; 1077 this.selectedDialCode.innerHTML = dialCode; 1078 // offsetWidth is zero if input is in a hidden container during initialisation 1079 var selectedFlagWidth = this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth(); 1080 // add 6px of padding after the grey selected-dial-code box, as this is what we use in the css 1081 // this.telInput.style.paddingLeft = "".concat(selectedFlagWidth + 6, "px"); 1082 var padding_left = "".concat(selectedFlagWidth + 6, "px"); 1083 this.telInput.style.setProperty("padding-left", padding_left, "important"); 1084 } 1085 // and the input's placeholder 1086 this._updatePlaceholder(); 1087 // update the active list item 1088 if (this.options.allowDropdown) { 1089 var prevItem = this.activeItem; 1090 if (prevItem) { 1091 prevItem.classList.remove("iti__active"); 1092 prevItem.setAttribute("aria-selected", "false"); 1093 } 1094 if (countryCode) { 1095 // check if there is a preferred item first, else fall back to standard 1096 var nextItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(countryCode, "-preferred")) || this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(countryCode)); 1097 if(nextItem != null) 1098 { 1099 nextItem.setAttribute("aria-selected", "true"); 1100 nextItem.classList.add("iti__active"); 1101 this.activeItem = nextItem; 1102 this.selectedFlag.setAttribute("aria-activedescendant", nextItem.getAttribute("id")); 1103 } 1104 } 1105 } 1106 // return if the flag has changed or not 1107 return prevCountry.iso2 !== countryCode; 1108 } 1109 }, { 1110 key: "_getHiddenSelectedFlagWidth", 1111 value: function _getHiddenSelectedFlagWidth() 1112 { 1113 // to get the right styling to apply, all we need is a shallow clone of the container, 1114 // and then to inject a deep clone of the selectedFlag element 1115 var containerClone = this.telInput.parentNode.cloneNode(); 1116 containerClone.style.visibility = "hidden"; 1117 document.body.appendChild(containerClone); 1118 var flagsContainerClone = this.flagsContainer.cloneNode(); 1119 containerClone.appendChild(flagsContainerClone); 1120 var selectedFlagClone = this.selectedFlag.cloneNode(true); 1121 flagsContainerClone.appendChild(selectedFlagClone); 1122 var width = selectedFlagClone.offsetWidth; 1123 containerClone.parentNode.removeChild(containerClone); 1124 return width; 1125 } 1126 }, { 1127 key: "_updatePlaceholder", 1128 value: function _updatePlaceholder() 1129 { 1130 var shouldSetPlaceholder = this.options.autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && this.options.autoPlaceholder === "polite"; 1131 if (window.intlTelInputUtils && shouldSetPlaceholder) { 1132 var numberType = intlTelInputUtils.numberType[this.options.placeholderNumberType]; 1133 var placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, this.options.nationalMode, numberType) : ""; 1134 placeholder = this._beforeSetNumber(placeholder); 1135 if (typeof this.options.customPlaceholder === "function") { 1136 placeholder = this.options.customPlaceholder(placeholder, this.selectedCountryData); 1137 } 1138 this.telInput.setAttribute("placeholder", placeholder); 1139 } 1140 } 1141 }, { 1142 key: "_selectListItem", 1143 value: function _selectListItem(listItem) 1144 { 1145 // update selected flag and active list item 1146 var flagChanged = this._setFlag(listItem.getAttribute("data-country-code")); 1147 this._closeDropdown(); 1148 this._updateDialCode(listItem.getAttribute("data-dial-code"), true); 1149 // focus the input 1150 this.telInput.focus(); 1151 // put cursor at end - this fix is required for FF and IE11 (with nationalMode=false i.e. auto 1152 // inserting dial code), who try to put the cursor at the beginning the first time 1153 var len = this.telInput.value.length; 1154 this.telInput.setSelectionRange(len, len); 1155 if (flagChanged) { 1156 this._triggerCountryChange(); 1157 } 1158 } 1159 }, { 1160 key: "_closeDropdown", 1161 value: function _closeDropdown() 1162 { 1163 this.countryList.classList.add("iti__hide"); 1164 this.selectedFlag.setAttribute("aria-expanded", "false"); 1165 // update the arrow 1166 this.dropdownArrow.classList.remove("iti__arrow--up"); 1167 // unbind key events 1168 document.removeEventListener("keydown", this._handleKeydownOnDropdown); 1169 document.documentElement.removeEventListener("click", this._handleClickOffToClose); 1170 this.countryList.removeEventListener("mouseover", this._handleMouseoverCountryList); 1171 this.countryList.removeEventListener("click", this._handleClickCountryList); 1172 // remove menu from container 1173 if (this.options.dropdownContainer) { 1174 if (!this.isMobile) { window.removeEventListener("scroll", this._handleWindowScroll); 1175 } 1176 if (this.dropdown.parentNode) { this.dropdown.parentNode.removeChild(this.dropdown); 1177 } 1178 } 1179 this._trigger("close:countrydropdown"); 1180 } 1181 }, { 1182 key: "_scrollTo", 1183 value: function _scrollTo(element, middle) 1184 { 1185 var container = this.countryList; 1186 // windowTop from https://stackoverflow.com/a/14384091/2
vendor: 15,649 bytes, lines 1186-1464
118617866 1187 var windowTop = window.pageYOffset || document.documentElement.scrollTop; 1188 var containerHeight = container.offsetHeight; 1189 var containerTop = container.getBoundingClientRect().top + windowTop; 1190 var containerBottom = containerTop + containerHeight; 1191 var elementHeight = element.offsetHeight; 1192 var elementTop = element.getBoundingClientRect().top + windowTop; 1193 var elementBottom = elementTop + elementHeight; 1194 var newScrollTop = elementTop - containerTop + container.scrollTop; 1195 var middleOffset = containerHeight / 2 - elementHeight / 2; 1196 if (elementTop < containerTop) { 1197 // scroll up 1198 if (middle) { newScrollTop -= middleOffset; 1199 } 1200 container.scrollTop = newScrollTop; 1201 } else if (elementBottom > containerBottom) { 1202 // scroll down 1203 if (middle) { newScrollTop += middleOffset; 1204 } 1205 var heightDifference = containerHeight - elementHeight; 1206 container.scrollTop = newScrollTop - heightDifference; 1207 } 1208 } 1209 }, { 1210 key: "_updateDialCode", 1211 value: function _updateDialCode(newDialCodeBare, hasSelectedListItem) 1212 { 1213 var inputVal = this.telInput.value; 1214 // save having to pass this every time 1215 var newDialCode = "+".concat(newDialCodeBare); 1216 var newNumber; 1217 if (inputVal.charAt(0) === "+") { 1218 // there's a plus so we're dealing with a replacement (doesn't matter if nationalMode or not) 1219 var prevDialCode = this._getDialCode(inputVal); 1220 if (prevDialCode) { 1221 // current number contains a valid dial code, so replace it 1222 newNumber = inputVal.replace(prevDialCode, newDialCode); 1223 } else { 1224 // current number contains an invalid dial code, so ditch it 1225 // (no way to determine where the invalid dial code ends and the rest of the number begins) 1226 newNumber = newDialCode; 1227 } 1228 } else if (this.options.nationalMode || this.options.separateDialCode) { 1229 // don't do anything 1230 return; 1231 } else { 1232 // nationalMode is disabled 1233 if (inputVal) { 1234 // there is an existing value with no dial code: prefix the new dial code 1235 newNumber = newDialCode + inputVal; 1236 } else if (hasSelectedListItem || !this.options.autoHideDialCode) { 1237 // no existing value and either they've just selected a list item, or autoHideDialCode is 1238 // disabled: insert new dial code 1239 newNumber = newDialCode; 1240 } else { 1241 return; 1242 } 1243 } 1244 this.telInput.value = newNumber; 1245 } 1246 }, { 1247 key: "_getDialCode", 1248 value: function _getDialCode(number, includeAreaCode) 1249 { 1250 var dialCode = ""; 1251 // only interested in international numbers (starting with a plus) 1252 if (number.charAt(0) === "+") { 1253 var numericChars = ""; 1254 // iterate over chars 1255 for (var i = 0; i < number.length; i++) { 1256 var c = number.charAt(i); 1257 // if char is number (https://stackoverflow.com/a/8935649/217866) 1258 if (!isNaN(parseInt(c, 10))) { 1259 numericChars += c; 1260 // if current numericChars make a valid dial code 1261 if (includeAreaCode) { 1262 if (this.countryCodes[numericChars]) { 1263 // store the actual raw string (useful for matching later) 1264 dialCode = number.substr(0, i + 1); 1265 } 1266 } else { 1267 if (this.dialCodes[numericChars]) { 1268 dialCode = number.substr(0, i + 1); 1269 // if we're just looking for a dial code, we can break as soon as we find one 1270 break; 1271 } 1272 } 1273 // stop searching as soon as we can - in this case when we hit max len 1274 if (numericChars.length === this.countryCodeMaxLen) { 1275 break; 1276 } 1277 } 1278 } 1279 } 1280 return dialCode; 1281 } 1282 }, { 1283 key: "_getFullNumber", 1284 value: function _getFullNumber() 1285 { 1286 var val = this.telInput.value.trim(); 1287 var dialCode = this.selectedCountryData.dialCode; 1288 var prefix; 1289 var numericVal = this._getNumeric(val); 1290 if (this.options.separateDialCode && val.charAt(0) !== "+" && dialCode && numericVal) { 1291 prefix = "+".concat(dialCode); 1292 var newNumber = prefix + val; 1293 if(!intlTelInputUtils.isValidNumber(newNumber, dialCode)) 1294 { 1295 prefix = ""; 1296 } 1297 } else { 1298 prefix = ""; 1299 } 1300 return prefix + val; 1301 } 1302 }, { 1303 key: "_beforeSetNumber", 1304 value: function _beforeSetNumber(originalNumber) 1305 { 1306 var number = originalNumber; 1307 if (this.options.separateDialCode) { 1308 var dialCode = this._getDialCode(number); 1309 // if there is a valid dial code 1310 if (dialCode) { 1311 // in case _getDialCode returned an area code as well 1312 dialCode = "+".concat(this.selectedCountryData.dialCode); 1313 // a lot of numbers will have a space separating the dial code and the main number, and 1314 // some NANP numbers will have a hyphen e.g. +1 684-733-1234 - in both cases we want to get 1315 // rid of it 1316 // NOTE: don't just trim all non-numerics as may want to preserve an open parenthesis etc 1317 var start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length; 1318 number = number.substr(start); 1319 } 1320 } 1321 return this._cap(number); 1322 } 1323 }, { 1324 key: "_triggerCountryChange", 1325 value: function _triggerCountryChange() 1326 { 1327 this._trigger("countrychange"); 1328 } 1329 }, { 1330 key: "handleAutoCountry", 1331 value: function handleAutoCountry() 1332 { 1333 if (this.options.initialCountry === "auto") { 1334 // we must set this even if there is an initial val in the input: in case the initial val is 1335 // invalid and they delete it - they should see their auto country 1336 this.defaultCountry = window.intlTelInputGlobals.autoCountry; 1337 // if there's no initial value in the input, then update the flag 1338 if (!this.telInput.value) { 1339 this.setCountry(this.defaultCountry); 1340 } 1341 this.resolveAutoCountryPromise(); 1342 } 1343 } 1344 }, { 1345 key: "handleUtils", 1346 value: function handleUtils() 1347 { 1348 // if the request was successful 1349 if (window.intlTelInputUtils) { 1350 // if there's an initial value in the input, then format it 1351 if (this.telInput.value) { 1352 this._updateValFromNumber(this.telInput.value); 1353 } 1354 this._updatePlaceholder(); 1355 } 1356 this.resolveUtilsScriptPromise(); 1357 } 1358 }, { 1359 key: "destroy", 1360 value: function destroy() 1361 { 1362 var form = this.telInput.form; 1363 if (this.options.allowDropdown) { 1364 // make sure the dropdown is closed (and unbind listeners) 1365 this._closeDropdown(); 1366 this.selectedFlag.removeEventListener("click", this._handleClickSelectedFlag); 1367 this.flagsContainer.removeEventListener("keydown", this._handleFlagsContainerKeydown); 1368 // label click hack 1369 var label = this._getClosestLabel(); 1370 if (label) { label.removeEventListener("click", this._handleLabelClick); 1371 } 1372 } 1373 // unbind hiddenInput listeners 1374 if (this.hiddenInput && form) { form.removeEventListener("submit", this._handleHiddenInputSubmit); 1375 } 1376 // unbind autoHideDialCode listeners 1377 if (this.options.autoHideDialCode) { 1378 if (form) { form.removeEventListener("submit", this._handleSubmitOrBlurEvent); 1379 } 1380 this.telInput.removeEventListener("blur", this._handleSubmitOrBlurEvent); 1381 } 1382 // unbind key events, and cut/paste events 1383 this.telInput.removeEventListener("keyup", this._handleKeyupEvent); 1384 this.telInput.removeEventListener("cut", this._handleClipboardEvent); 1385 this.telInput.removeEventListener("paste", this._handleClipboardEvent); 1386 // remove attribute of id instance: data-intl-tel-input-id 1387 this.telInput.removeAttribute("data-intl-tel-input-id"); 1388 // remove markup (but leave the original input) 1389 var wrapper = this.telInput.parentNode; 1390 wrapper.parentNode.insertBefore(this.telInput, wrapper); 1391 wrapper.parentNode.removeChild(wrapper); 1392 delete window.intlTelInputGlobals.instances[this.id]; 1393 } 1394 }, { 1395 key: "getExtension", 1396 value: function getExtension() 1397 { 1398 if (window.intlTelInputUtils) { 1399 return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2); 1400 } 1401 return ""; 1402 } 1403 }, { 1404 key: "getNumber", 1405 value: function getNumber(format) 1406 { 1407 if (window.intlTelInputUtils) { 1408 var iso2 = this.selectedCountryData.iso2; 1409 return intlTelInputUtils.formatNumber(this._getFullNumber(), iso2, format); 1410 } 1411 return ""; 1412 } 1413 }, { 1414 key: "getNumberType", 1415 value: function getNumberType() 1416 { 1417 if (window.intlTelInputUtils) { 1418 return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2); 1419 } 1420 return -99; 1421 } 1422 }, { 1423 key: "getSelectedCountryData", 1424 value: function getSelectedCountryData() 1425 { 1426 return this.selectedCountryData; 1427 } 1428 }, { 1429 key: "getValidationError", 1430 value: function getValidationError() 1431 { 1432 if (window.intlTelInputUtils) { 1433 var iso2 = this.selectedCountryData.iso2; 1434 return intlTelInputUtils.getValidationError(this._getFullNumber(), iso2); 1435 } 1436 return -99; 1437 } 1438 }, { 1439 key: "isValidNumber", 1440 value: function isValidNumber() 1441 { 1442 var val = this._getFullNumber().trim(); 1443 var countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : ""; 1444 return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null; 1445 } 1446 }, { 1447 key: "setCountry", 1448 value: function setCountry(originalCountryCode) 1449 { 1450 var countryCode = originalCountryCode.toLowerCase(); 1451 // check if already selected 1452 //if (this.selectedFlagInner !== undefined && !this.selectedFlagInner.classList.contains("iti__".concat(countryCode))) { 1453 this._setFlag(countryCode); 1454 this._updateDialCode(this.selectedCountryData.dialCode, false); 1455 this._triggerCountryChange(); 1456 //} 1457 } 1458 }, { 1459 key: "setNumber", 1460 value: function setNumber(number) 1461 { 1462 // we must update the flag first, which updates this.selectedCountryData, which is used for 1463 // formatting the number before displaying it 1464 var flagChanged = this._updateFlagFromNumber(number);
1465 this._updateValFromNumber(number); 1466 if (flagChanged) { 1467 this._triggerCountryChange(); 1468 } 1469 } 1470 }, { 1471 key: "setPlaceholderNumberType", 1472 value: function setPlaceholderNumberType(type) 1473 { 1474 this.options.placeholderNumberType = type; 1475 this._updatePlaceholder(); 1476 } 1477 } ] 1478 ); 1479 return Iti; 1480 }(); 1481 /******************** 1482 * STATIC METHODS 1483 ********************/ 1484 // get the country data object 1485 intlTelInputGlobals.getCountryData = function () { 1486 return allCountries; 1487 }; 1488 // inject a <script> element to load utils.js 1489 var injectScript = function injectScript(path, handleSuccess, handleFailure) 1490 { 1491 // inject a new script element into the page 1492 var script = document.createElement("script"); 1493 script.onload = function () { 1494 forEachInstance("handleUtils"); 1495 if (handleSuccess) { handleSuccess(); 1496 } 1497 }; 1498 script.onerror = function () { 1499 forEachInstance("rejectUtilsScriptPromise"); 1500 if (handleFailure) { handleFailure(); 1501 } 1502 }; 1503 script.className = "iti-load-utils"; 1504 script.async = true; 1505 script.src = path; 1506 document.body.appendChild(script); 1507 }; 1508 // load the utils script 1509 intlTelInputGlobals.loadUtils = function (path) { 1510 // 2 options: 1511 // 1) not already started loading (start) 1512 // 2) already started loading (do nothing - just wait for the onload callback to fire, which will 1513 // trigger handleUtils on all instances, invoking their resolveUtilsScriptPromise functions) 1514 if (!window.intlTelInputUtils && !window.intlTelInputGlobals.startedLoadingUtilsScript) { 1515 // only do this once 1516 window.intlTelInputGlobals.startedLoadingUtilsScript = true; 1517 // if we have promises, then return a promise 1518 if (typeof Promise !== "undefined") { 1519 return new Promise( 1520 function (resolve, reject) { 1521 return injectScript(path, resolve, reject); 1522 } 1523 ); 1524 } 1525 injectScript(path); 1526 } 1527 return null; 1528 }; 1529 // default options 1530 intlTelInputGlobals.defaults = defaults; 1531 // version 1532 intlTelInputGlobals.version = "17.0.8"; 1533 var pluginName = "intlTelInput"; 1534 // A really lightweight plugin wrapper around the constructor, 1535 // preventing against multiple instantiations 1536 $.fn[pluginName] = function (options) { 1537 var args = arguments; 1538 // Is the first parameter an object (options), or was omitted, instantiate a new instance of the plugin. 1539 if (options === undefined || typeof options === "object") { 1540 return this.each( 1541 function () { 1542 if (!$.data(this, "plugin_" + pluginName)) { 1543 var iti = new Iti(this, options); 1544 iti._init(); 1545 window.intlTelInputGlobals.instances[iti.id] = iti; 1546 $.data(this, "plugin_" + pluginName, iti); 1547 } 1548 } 1549 ); 1550 } else if (typeof options === "string" && options[0] !== "_") { 1551 // If the first parameter is a string and it doesn't start with an underscore treat this as a call to a public method. 1552 // Cache the method call to make it possible to return a value 1553 var returns; 1554 this.each( 1555 function () { 1556 var instance = $.data(this, "plugin_" + pluginName); 1557 // Tests that there's already a plugin-instance and checks that the requested public method exists 1558 if (instance instanceof Iti && typeof instance[options] === "function") { 1559 // Call the method of our plugin instance, and pass it the supplied arguments. 1560 returns = instance[options].apply(instance, Array.prototype.slice.call(args, 1)); 1561 } 1562 // Allow instances to be destroyed via the 'destroy' method 1563 if (options === "destroy") { $.data(this, "plugin_" + pluginName, null); 1564 } 1565 } 1566 ); 1567 // If the earlier cached method gives a value back return the value, otherwise return this to preserve chainability. 1568 return returns !== undefined ? returns : this; 1569 } 1570 }; 1571 } 1572);
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.