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