Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

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