PageSourceSearch

https://www.edreams.co.uk/content/img/OF/WebMasterPages/merch/app/sms-send/intlTelInput-jquery.js

js edreams.co.uk collected 2026-09-28 09:19:45 UTC 84,105 bytes, 1,362 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.