PageSourceSearch

https://www.edreams.com/content/img/OF/WebMasterPages/merch/app/sms-form/intlTelInput.js

js edreams.com collected 2026-10-01 12:15:24 UTC 92,758 bytes, 1,333 lines download raw bytes

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

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.