PageSourceSearch

https://delta8studio.com/additions/assets/css/new/form/intlTelInput.js

js delta8studio.com collected 2026-09-24 14:41:33 UTC 69,578 bytes, 1,119 lines download raw bytes

1/*
2 * International Telephone Input v10.0.2
3 * https://github.com/jackocnr/intl-tel-input.git
4 * Licensed under the MIT license
5 */
6// wrap in UMD - see https://github.com/umdjs/umd/blob/master/jqueryPluginCommonjs.js
7(function(factory) {
8    if (typeof define === "function" && define.amd) {
9        define([ "jquery" ], function($) {
10            factory($, window, document);
11        });
12    } else if (typeof module === "object" && module.exports) {
13        module.exports = factory(require("jquery"), window, document);
14    } else {
15        factory(jQuery, window, document);
16    }
17})(function($, window, document, undefined) {
18    "use strict";
19    // these vars persist through all instances of the plugin
20    var pluginName = "intlTelInput", id = 1, // give each instance it's own id for namespaced event handling
21    defaults = {
22        // whether or not to allow the dropdown
23        allowDropdown: true,
24        // if there is just a dial code in the input: remove it on blur, and re-add it on focus
25        autoHideDialCode: true,
26        // add a placeholder in the input with an example number for the selected country
27        autoPlaceholder: "polite",
28        // modify the auto placeholder
29        customPlaceholder: null,
30        // append menu to a specific element
31        dropdownContainer: "",
32        // don't display these countries
33        excludeCountries: [],
34        // format the input value during initialisation and on setNumber
35        formatOnDisplay: true,
36        // geoIp lookup function
37        geoIpLookup: null,
38        // initial country
39        initialCountry: "",
40        // don't insert international dial codes
41        nationalMode: true,
42        // display only these countries
43        onlyCountries: [],
44        // number type to use for placeholders
45        placeholderNumberType: "MOBILE",
46        // the countries at the top of the list. defaults to united states and united kingdom
47        preferredCountries: [ "us", "gb" ],
48        // display the country dial code next to the selected flag so it's not part of the typed number
49        separateDialCode: false,
50        // specify the path to the libphonenumber script to enable validation/formatting
51        utilsScript: ""
52    }, keys = {
53        UP: 38,
54        DOWN: 40,
55        ENTER: 13,
56        ESC: 27,
57        PLUS: 43,
58        A: 65,
59        Z: 90,
60        SPACE: 32,
61        TAB: 9
62    }, regionlessNanpNumbers = [ "800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889" ];
63    // keep track of if the window.load event has fired as impossible to check after the fact
64    $(window).on("load", function() {
65        // UPDATE: use a public static field so we can fudge it in the tests
66        $.fn[pluginName].windowLoaded = true;
67    });
68    function Plugin(element, options) {
69        this.telInput = $(element);
70        this.options = $.extend({}, defaults, options);
71        // event namespace
72        this.ns = "." + pluginName + id++;
73        // Chrome, FF, Safari, IE9+
74        this.isGoodBrowser = Boolean(element.setSelectionRange);
75        this.hadInitialPlaceholder = Boolean($(element).attr("placeholder"));
76    }
77    Plugin.prototype = {
78        _init: function() {
79            // if in nationalMode, disable options relating to dial codes
80            if (this.options.nationalMode) {
81                this.options.autoHideDialCode = false;
82            }
83            // if separateDialCode then doesn't make sense to A) insert dial code into input (autoHideDialCode), and B) display national numbers (because we're displaying the country dial code next to them)
84            if (this.options.separateDialCode) {
85                this.options.autoHideDialCode = this.options.nationalMode = false;
86            }
87            // we cannot just test screen size as some smartphones/website meta tags will report desktop resolutions
88            // Note: for some reason jasmine breaks if you put this in the main Plugin function with the rest of these declarations
89            // Note: to target Android Mobiles (and not Tablets), we must find "Android" and "Mobile"
90            this.isMobile = /Android.+Mobile|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
91            if (this.isMobile) {
92                // trigger the mobile dropdown css
93                $("body").addClass("iti-mobile");
94                // on mobile, we want a full screen dropdown, so we must append it to the body
95                if (!this.options.dropdownContainer) {
96                    this.options.dropdownContainer = "body";
97                }
98            }
99            // we return these deferred objects from the _init() call so they can be watched, and then we resolve them when each specific request returns
100            // Note: again, jasmine breaks when I put these in the Plugin function
101            this.autoCountryDeferred = new $.Deferred();
102            this.utilsScriptDeferred = new $.Deferred();
103            // process all the data: onlyCountries, excludeCountries, preferredCountries etc
104            this._processCountryData();
105            // generate the markup
106            this._generateMarkup();
107            // set the initial state of the input value and the selected flag
108            this._setInitialState();
109            // start all of the event listeners: autoHideDialCode, input keydown, selectedFlag click
110            this._initListeners();
111            // utils script, and auto country
112            this._initRequests();
113            // return the deferreds
114            return [ this.autoCountryDeferred, this.utilsScriptDeferred ];
115        },
116        /********************
117   *  PRIVATE METHODS
118   ********************/
119        // prepare all of the country data, including onlyCountries, excludeCountries and preferredCountries options
120        _processCountryData: function() {
121            // process onlyCountries or excludeCountries array if present
122            this._processAllCountries();
123            // process the countryCodes map
124            this._processCountryCodes();
125            // process the preferredCountries
126            this._processPreferredCountries();
127        },
128        // add a country code to this.countryCodes
129        _addCountryCode: function(iso2, dialCode, priority) {
130            if (!(dialCode in this.countryCodes)) {
131                this.countryCodes[dialCode] = [];
132            }
133            var index = priority || 0;
134            this.countryCodes[dialCode][index] = iso2;
135        },
136        // filter the given countries using the process function
137        _filterCountries: function(countryArray, processFunc) {
138            var i;
139            // standardise case
140            for (i = 0; i < countryArray.length; i++) {
141                countryArray[i] = countryArray[i].toLowerCase();
142            }
143            // build instance country array
144            this.countries = [];
145            for (i = 0; i < allCountries.length; i++) {
146                if (processFunc(countryArray.indexOf(allCountries[i].iso2))) {
147                    this.countries.push(allCountries[i]);
148                }
149            }
150        },
151        // process onlyCountries or excludeCountries array if present
152        _processAllCountries: function() {
153            if (this.options.onlyCountries.length) {
154                // process onlyCountries option
155                this._filterCountries(this.options.onlyCountries, function(arrayPos) {
156                    // if country is in array
157                    return arrayPos > -1;
158                });
159            } else if (this.options.excludeCountries.length) {
160                // process excludeCountries option
161                this._filterCountries(this.options.excludeCountries, function(arrayPos) {
162                    // if country is not in array
163                    return arrayPos == -1;
164                });
165            } else {
166                this.countries = allCountries;
167            }
168        },
169        // process the countryCodes map
170        _processCountryCodes: function() {
171            this.countryCodes = {};
172            for (var i = 0; i < this.countries.length; i++) {
173                var c = this.countries[i];
174                this._addCountryCode(c.iso2, c.dialCode, c.priority);
175                // area codes
176                if (c.areaCodes) {
177                    for (var j = 0; j < c.areaCodes.length; j++) {
178                        // full dial code is country code + dial code
179                        this._addCountryCode(c.iso2, c.dialCode + c.areaCodes[j]);
180                    }
181                }
182            }
183        },
184        // process preferred countries - iterate through the preferences, fetching the country data for each one
185        _processPreferredCountries: function() {
186            this.preferredCountries = [];
187            for (var i = 0; i < this.options.preferredCountries.length; i++) {
188                var countryCode = this.options.preferredCountries[i].toLowerCase(), countryData = this._getCountryData(countryCode, false, true);
189                if (countryData) {
190                    this.preferredCountries.push(countryData);
191                }
192            }
193        },
194        // generate all of the markup for the plugin: the selected flag overlay, and the dropdown
195        _generateMarkup: function() {
196            // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can easily put the plugin in an inconsistent state e.g. the wrong flag selected for the autocompleted number, which on submit could mean the wrong number is saved (esp in nationalMode)
197            this.telInput.attr("autocomplete", "off");
198            // containers (mostly for positioning)
199            var parentClass = "intl-tel-input";
200            if (this.options.allowDropdown) {
201                parentClass += " allow-dropdown";
202            }
203            if (this.options.separateDialCode) {
204                parentClass += " separate-dial-code";
205            }
206            this.telInput.wrap($("<div>", {
207                "class": parentClass
208            }));
209            this.flagsContainer = $("<div>", {
210                "class": "flag-container"
211            }).insertBefore(this.telInput);
212            // currently selected flag (displayed to left of input)
213            var selectedFlag = $("<div>", {
214                "class": "selected-flag"
215            });
216            selectedFlag.appendTo(this.flagsContainer);
217            this.selectedFlagInner = $("<div>", {
218                "class": "iti-flag"
219            }).appendTo(selectedFlag);
220            if (this.options.separateDialCode) {
221                this.selectedDialCode = $("<div>", {
222                    "class": "selected-dial-code"
223                }).appendTo(selectedFlag);
224            }
225            if (this.options.allowDropdown) {
226                // make element focusable and tab naviagable
227                selectedFlag.attr("tabindex", "0");
228                // CSS triangle
229                $("<div>", {
230                    "class": "iti-arrow"
231                }).appendTo(selectedFlag);
232                // country dropdown: preferred countries, then divider, then all countries
233                this.countryList = $("<ul>", {
234                    "class": "country-list hide"
235                });
236                if (this.preferredCountries.length) {
237                    this._appendListItems(this.preferredCountries, "preferred");
238                    $("<li>", {
239                        "class": "divider"
240                    }).appendTo(this.countryList);
241                }
242                this._appendListItems(this.countries, "");
243                // this is useful in lots of places
244                this.countryListItems = this.countryList.children(".country");
245                // create dropdownContainer markup
246                if (this.options.dropdownContainer) {
247                    this.dropdown = $("<div>", {
248                        "class": "intl-tel-input iti-container"
249                    }).append(this.countryList);
250                } else {
251                    this.countryList.appendTo(this.flagsContainer);
252                }
253            } else {
254                // a little hack so we don't break anything
255                this.countryListItems = $();
256            }
257        },
258        // add a country <li> to the countryList <ul> container
259        _appendListItems: function(countries, className) {
260            // we create so many DOM elements, it is faster to build a temp string
261            // and then add everything to the DOM in one go at the end
262            var tmp = "";
263            // for each country
264            for (var i = 0; i < countries.length; i++) {
265                var c = countries[i];
266                // open the list item
267                tmp += "<li class='country " + className + "' data-dial-code='" + c.dialCode + "' data-country-code='" + c.iso2 + "'>";
268                // add the flag
269                tmp += "<div class='flag-box'><div class='iti-flag " + c.iso2 + "'></div></div>";
270                // and the country name and dial code
271                tmp += "<span class='country-name'>" + c.name + "</span>";
272                tmp += "<span class='dial-code'>+" + c.dialCode + "</span>";
273                // close the list item
274                tmp += "</li>";
275            }
276            this.countryList.append(tmp);
277        },
278        // set the initial state of the input value and the selected flag by:
279        // 1. extracting a dial code from the given number
280        // 2. using explicit initialCountry
281        // 3. picking the first preferred country
282        // 4. picking the first country
283        _setInitialState: function() {
284            var val = this.telInput.val();
285            // if we already have a dial code, and it's not a regionlessNanp we can go ahead and set the flag, else fall back to default
286            if (this._getDialCode(val) && !this._isRegionlessNanp(val)) {
287                this._updateFlagFromNumber(val);
288            } else if (this.options.initialCountry !== "auto") {
289                // see if we should select a flag
290                if (this.options.initialCountry) {
291                    this._setFlag(this.options.initialCountry.toLowerCase());
292                } else {
293                    // no dial code and no initialCountry, so default to first in list
294                    this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2;
295                    if (!val) {
296                        this._setFlag(this.defaultCountry);
297                    }
298                }
299                // if empty and no nationalMode and no autoHideDialCode then insert the default dial code
300                if (!val && !this.options.nationalMode && !this.options.autoHideDialCode && !this.options.separateDialCode) {
301                    this.telInput.val("+" + this.selectedCountryData.dialCode);
302                }
303            }
304            // NOTE: if initialCountry is set to auto, that will be handled separately
305            // format
306            if (val) {
307                // this wont be run after _updateDialCode as that's only called 
307if no val
308                this._updateValFromNumber(val);
309            }
310        },
311        // initialise the main event listeners: input keyup, and click selected flag
312        _initListeners: function() {
313            this._initKeyListeners();
314            if (this.options.autoHideDialCode) {
315                this._initFocusListeners();
316            }
317            if (this.options.allowDropdown) {
318                this._initDropdownListeners();
319            }
320        },
321        // initialise the dropdown listeners
322        _initDropdownListeners: function() {
323            var that = this;
324            // hack for input nested inside label: clicking the selected-flag to open the dropdown would then automatically trigger a 2nd click on the input which would close it again
325            var label = this.telInput.closest("label");
326            if (label.length) {
327                label.on("click" + this.ns, function(e) {
328                    // if the dropdown is closed, then focus the input, else ignore the click
329                    if (that.countryList.hasClass("hide")) {
330                        that.telInput.focus();
331                    } else {
332                        e.preventDefault();
333                    }
334                });
335            }
336            // toggle country dropdown on click
337            var selectedFlag = this.selectedFlagInner.parent();
338            selectedFlag.on("click" + this.ns, function(e) {
339                // only intercept this event if we're opening the dropdown
340                // else let it bubble up to the top ("click-off-to-close" listener)
341                // we cannot just stopPropagation as it may be needed to close another instance
342                if (that.countryList.hasClass("hide") && !that.telInput.prop("disabled") && !that.telInput.prop("readonly")) {
343                    that._showDropdown();
344                }
345            });
346            // open dropdown list if currently focused
347            this.flagsContainer.on("keydown" + that.ns, function(e) {
348                var isDropdownHidden = that.countryList.hasClass("hide");
349                if (isDropdownHidden && (e.which == keys.UP || e.which == keys.DOWN || e.which == keys.SPACE || e.which == keys.ENTER)) {
350                    // prevent form from being submitted if "ENTER" was pressed
351                    e.preventDefault();
352                    // prevent event from being handled again by document
353                    e.stopPropagation();
354                    that._showDropdown();
355                }
356                // allow navigation from dropdown to input on TAB
357                if (e.which == keys.TAB) {
358                    that._closeDropdown();
359                }
360            });
361        },
362        // init many requests: utils script / geo ip lookup
363        _initRequests: function() {
364            var that = this;
365            // if the user has specified the path to the utils script, fetch it on window.load, else resolve
366            if (this.options.utilsScript) {
367                // if the plugin is being initialised after the window.load event has already been fired
368                if ($.fn[pluginName].windowLoaded) {
369                    $.fn[pluginName].loadUtils(this.options.utilsScript, this.utilsScriptDeferred);
370                } else {
371                    // wait until the load event so we don't block any other requests e.g. the flags image
372                    $(window).on("load", function() {
373                        $.fn[pluginName].loadUtils(that.options.utilsScript, that.utilsScriptDeferred);
374                    });
375                }
376            } else {
377                this.utilsScriptDeferred.resolve();
378            }
379            if (this.options.initialCountry === "auto") {
380                this._loadAutoCountry();
381            } else {
382                this.autoCountryDeferred.resolve();
383            }
384        },
385        // perform the geo ip lookup
386        _loadAutoCountry: function() {
387            var that = this;
388            // 3 options:
389            // 1) already loaded (we're done)
390            // 2) not already started loading (start)
391            // 3) already started loading (do nothing - just wait for loading callback to fire)
392            if ($.fn[pluginName].autoCountry) {
393                this.handleAutoCountry();
394            } else if (!$.fn[pluginName].startedLoadingAutoCountry) {
395                // don't do this twice!
396                $.fn[pluginName].startedLoadingAutoCountry = true;
397                if (typeof this.options.geoIpLookup === "function") {
398                    this.options.geoIpLookup(function(countryCode) {
399                        $.fn[pluginName].autoCountry = countryCode.toLowerCase();
400                        // tell all instances the auto country is ready
401                        // TODO: this should just be the current instances
402                        // UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight away (e.g. if they have already done the geo ip lookup somewhere else). Using setTimeout means that the current thread of execution will finish before executing this, which allows the plugin to finish initialising.
403                        setTimeout(function() {
404                            $(".intl-tel-input input").intlTelInput("handleAutoCountry");
405                        });
406                    });
407                }
408            }
409        },
410        // initialize any key listeners
411        _initKeyListeners: function() {
412            var that = this;
413            // update flag on keyup
414            // (keep this listener separate otherwise the setTimeout breaks all the tests)
415            this.telInput.on("keyup" + this.ns, function() {
416                if (that._updateFlagFromNumber(that.telInput.val())) {
417                    that._triggerCountryChange();
418                }
419            });
420            // update flag on cut/paste events (now supported in all major browsers)
421            this.telInput.on("cut" + this.ns + " paste" + this.ns, function() {
422                // hack because "paste" event is fired before input is updated
423                setTimeout(function() {
424                    if (that._updateFlagFromNumber(that.telInput.val())) {
425                        that._triggerCountryChange();
426                    }
427                });
428            });
429        },
430        // adhere to the input's maxlength attr
431        _cap: function(number) {
432            var max = this.telInput.attr("maxlength");
433            return max && number.length > max ? number.substr(0, max) : number;
434        },
435        // listen for mousedown, focus and blur
436        _initFocusListeners: function() {
437            var that = this;
438            // mousedown decides where the cursor goes, so if we're focusing we must preventDefault as we'll be inserting the dial code, and we want the cursor to be at the end no matter where they click
439            this.telInput.on("mousedown" + this.ns, function(e) {
440                if (!that.telInput.is(":focus") && !that.telInput.val()) {
441                    e.preventDefault();
442                    // but this also cancels the focus, so we must trigger that manually
443                    that.telInput.focus();
444                }
445            });
446            // on focus: if empty, insert the dial code for the currently selected flag
447            this.telInput.on("focus" + this.ns, function(e) {
448                if (!that.telInput.val() && !that.telInput.prop("readonly") && that.selectedCountryData.dialCode) {
449                    // insert the dial code
450                    that.telInput.val("+" + that.selectedCountryData.dialCode);
451                    // after auto-inserting a dial code, if the first key they hit is '+' then assume they are entering a new number, so remove the dial code. use keypress instead of keydown because keydown gets triggered for the shift key (required to hit the + key), and instead of keyup because that shows the new '+' before removing the old one
452                    that.telInput.one("keypress.plus" + that.ns, function(e) {
453                        if (e.which == keys.PLUS) {
454                            that.telInput.val("");
455                        }
456                    });
457                    // after tabbing in, make sure the cursor is at the end we must use setTimeout to get outside of the focus handler as it seems the selection happens after that
458                    setTimeout(function() {
459                        var input = that.telInput[0];
460                        if (that.isGoodBrowser) {
461                            var len = that.telInput.val().length;
462                            input.setSelectionRange(len, len);
463                        }
464                    });
465                }
466            });
467            // on blur or form submit: if just a dial code then remove it
468            var form = this.telInput.prop("form");
469            if (form) {
470                $(form).on("submit" + this.ns, function() {
471                    that._removeEmptyDialCode();
472                });
473            }
474            this.telInput.on("blur" + this.ns, function() {
475                that._removeEmptyDialCode();
476            });
477        },
478        _removeEmptyDialCode: function() {
479            var value = this.telInput.val(), startsPlus = value.charAt(0) == "+";
480            if (startsPlus) {
481                var numeric = this._getNumeric(value);
482                // if just a plus, or if just a dial code
483                if (!numeric || this.selectedCountryData.dialCode == numeric) {
484                    this.telInput.val("");
485                }
486            }
487            // remove the keypress listener we added on focus
488            this.telInput.off("keypress.plus" + this.ns);
489        },
490        // extract the numeric digits from the given string
491        _getNumeric: function(s) {
492            return s.replace(/\D/g, "");
493        },
494        // show the dropdown
495        _showDropdown: function() {
496            this._setDropdownPosition();
497            // update highlighting and scroll to active list item
498            var activeListItem = this.countryList.children(".active");
499            if (activeListItem.length) {
500                this._highlightListItem(activeListItem);
501                this._scrollTo(activeListItem);
502            }
503            // bind all the dropdown-related listeners: mouseover, click, click-off, keydown
504            this._bindDropdownListeners();
505            // update the arrow
506            this.selectedFlagInner.children(".iti-arrow").addClass("up");
507        },
508        // decide where to position dropdown (depends on position within viewport, and scroll)
509        _setDropdownPosition: function() {
510            var that = this;
511            if (this.options.dropdownContainer) {
512                this.dropdown.appendTo(this.options.dropdownContainer);
513            }
514            // show the menu and grab the dropdown height
515            this.dropdownHeight = this.countryList.removeClass("hide").outerHeight();
516            if (!this.isMobile) {
517                var pos = this.telInput.offset(), inputTop = pos.top, windowTop = $(window).scrollTop(), // dropdownFitsBelow = (dropdownBottom < windowBottom)
518                dropdownFitsBelow = inputTop + this.telInput.outerHeight() + this.dropdownHeight < windowTop + $(window).height(), dropdownFitsAbove = inputTop - this.dropdownHeight > windowTop;
519                // by default, the dropdown will be below the input. If we want to position it above the input, we add the dropup class.
520                this.countryList.toggleClass("dropup", !dropdownFitsBelow && dropdownFitsAbove);
521                // if dropdownContainer is enabled, calculate postion
522                if (this.options.dropdownContainer) {
523                    // by default the dropdown will be directly over the input because it's not in the flow. If we want to position it below, we need to add some extra top value.
524                    var extraTop = !dropdownFitsBelow && dropdownFitsAbove ? 0 : this.telInput.innerHe
524ight();
525                    // calculate placement
526                    this.dropdown.css({
527                        top: inputTop + extraTop,
528                        left: pos.left
529                    });
530                    // close menu on window scroll
531                    $(window).on("scroll" + this.ns, function() {
532                        that._closeDropdown();
533                    });
534                }
535            }
536        },
537        // we only bind dropdown listeners when the dropdown is open
538        _bindDropdownListeners: function() {
539            var that = this;
540            // when mouse over a list item, just highlight that one
541            // we add the class "highlight", so if they hit "enter" we know which one to select
542            this.countryList.on("mouseover" + this.ns, ".country", function(e) {
543                that._highlightListItem($(this));
544            });
545            // listen for country selection
546            this.countryList.on("click" + this.ns, ".country", function(e) {
547                that._selectListItem($(this));
548            });
549            // click off to close
550            // (except when this initial opening click is bubbling up)
551            // we cannot just stopPropagation as it may be needed to close another instance
552            var isOpening = true;
553            $("html").on("click" + this.ns, function(e) {
554                if (!isOpening) {
555                    that._closeDropdown();
556                }
557                isOpening = false;
558            });
559            // listen for up/down scrolling, enter to select, or letters to jump to country name.
560            // use keydown as keypress doesn't fire for non-char keys and we want to catch if they
561            // just hit down and hold it to scroll down (no keyup event).
562            // listen on the document because that's where key events are triggered if no input has focus
563            var query = "", queryTimer = null;
564            $(document).on("keydown" + this.ns, function(e) {
565                // prevent down key from scrolling the whole page,
566                // and enter key from submitting a form etc
567                e.preventDefault();
568                if (e.which == keys.UP || e.which == keys.DOWN) {
569                    // up and down to navigate
570                    that._handleUpDownKey(e.which);
571                } else if (e.which == keys.ENTER) {
572                    // enter to select
573                    that._handleEnterKey();
574                } else if (e.which == keys.ESC) {
575                    // esc to close
576                    that._closeDropdown();
577                } else if (e.which >= keys.A && e.which <= keys.Z || e.which == keys.SPACE) {
578                    // upper case letters (note: keyup/keydown only return upper case letters)
579                    // jump to countries that start with the query string
580                    if (queryTimer) {
581                        clearTimeout(queryTimer);
582                    }
583                    query += String.fromCharCode(e.which);
584                    that._searchForCountry(query);
585                    // if the timer hits 1 second, reset the query
586                    queryTimer = setTimeout(function() {
587                        query = "";
588                    }, 1e3);
589                }
590            });
591        },
592        // highlight the next/prev item in the list (and ensure it is visible)
593        _handleUpDownKey: function(key) {
594            var current = this.countryList.children(".highlight").first();
595            var next = key == keys.UP ? current.prev() : current.next();
596            if (next.length) {
597                // skip the divider
598                if (next.hasClass("divider")) {
599                    next = key == keys.UP ? next.prev() : next.next();
600                }
601                this._highlightListItem(next);
602                this._scrollTo(next);
603            }
604        },
605        // select the currently highlighted item
606        _handleEnterKey: function() {
607            var currentCountry = this.countryList.children(".highlight").first();
608            if (currentCountry.length) {
609                this._selectListItem(currentCountry);
610            }
611        },
612        // find the first list item whose name starts with the query string
613        _searchForCountry: function(query) {
614            for (var i = 0; i < this.countries.length; i++) {
615                if (this._startsWith(this.countries[i].name, query)) {
616                    var listItem = this.countryList.children("[data-country-code=" + this.countries[i].iso2 + "]").not(".preferred");
617                    // update highlighting and scroll
618                    this._highlightListItem(listItem);
619                    this._scrollTo(listItem, true);
620                    break;
621                }
622            }
623        },
624        // check if (uppercase) string a starts with string b
625        _startsWith: function(a, b) {
626            return a.substr(0, b.length).toUpperCase() == b;
627        },
628        // update the input's value to the given val (format first if possible)
629        // NOTE: this is called from _setInitialState, handleUtils and setNumber
630        _updateValFromNumber: function(number) {
631            if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) {
632                var format = !this.options.separateDialCode && (this.options.nationalMode || number.charAt(0) != "+") ? intlTelInputUtils.numberFormat.NATIONAL : intlTelInputUtils.numberFormat.INTERNATIONAL;
633                number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format);
634            }
635            number = this._beforeSetNumber(number);
636            this.telInput.val(number);
637        },
638        // check if need to select a new flag based on the given number
639        // Note: called from _setInitialState, keyup handler, setNumber
640        _updateFlagFromNumber: function(number) {
641            // if we're in nationalMode and we already have US/Canada selected, make sure the number starts with a +1 so _getDialCode will be able to extract the area code
642            // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag from the number), that means we're initialising the plugin with a number that already has a dial code, so fine to ignore this bit
643            if (number && this.options.nationalMode && this.selectedCountryData && this.selectedCountryData.dialCode == "1" && number.charAt(0) != "+") {
644                if (number.charAt(0) != "1") {
645                    number = "1" + number;
646                }
647                number = "+" + number;
648            }
649            // try and extract valid dial code from input
650            var dialCode = this._getDialCode(number), countryCode = null, numeric = this._getNumeric(number);
651            if (dialCode) {
652                // check if one of the matching countries is already selected
653                var countryCodes = this.countryCodes[this._getNumeric(dialCode)], alreadySelected = this.selectedCountryData && countryCodes.indexOf(this.selectedCountryData.iso2) > -1, // check if the given number contains an unknown area code from the North American Numbering Plan i.e. the only dialCode that could be extracted was +1 (instead of say +1204) and the actual number's length is >=4
654                isUnknownNanp = dialCode == "+1" && numeric.length >= 4;
655                // if a matching country is not already selected (or this is an unknown NANP area code) AND it's not a regionlessNanp: choose the first in the list
656                if ((!alreadySelected || isUnknownNanp) && !this._isRegionlessNanp(numeric)) {
657                    // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first non-empty index
658                    for (var j = 0; j < countryCodes.length; j++) {
659                        if (countryCodes[j]) {
660                            countryCode = countryCodes[j];
661                            break;
662                        }
663                    }
664                }
665            } else if (number.charAt(0) == "+" && numeric.length) {
666                // invalid dial code, so empty
667                // Note: use getNumeric here because the number has not been formatted yet, so could contain bad chars
668                countryCode = "";
669            } else if (!number || number == "+") {
670                // empty, or just a plus, so default
671                countryCode = this.defaultCountry;
672            }
673            if (countryCode !== null) {
674                return this._setFlag(countryCode);
675            }
676            return false;
677        },
678        // check if the given number is a regionless NANP number (expects the number to contain an international dial code)
679        _isRegionlessNanp: function(number) {
680            var numeric = this._getNumeric(number);
681            if (numeric.charAt(0) == "1") {
682                var areaCode = numeric.substr(1, 3);
683                return regionlessNanpNumbers.indexOf(areaCode) > -1;
684            }
685            return false;
686        },
687        // remove highlighting from other list items and highlight the given item
688        _highlightListItem: function(listItem) {
689            this.countryListItems.removeClass("highlight");
690            listItem.addClass("highlight");
691        },
692        // find the country data for the given country code
693        // the ignoreOnlyCountriesOption is only used during init() while parsing the onlyCountries array
694        _getCountryData: function(countryCode, ignoreOnlyCountriesOption, allowFail) {
695            var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries;
696            for (var i = 0; i < countryList.length; i++) {
697                if (countryList[i].iso2 == countryCode) {
698                    return countryList[i];
699                }
700            }
701            if (allowFail) {
702                return null;
703            } else {
704                throw new Error("No country data for '" + countryCode + "'");
705            }
706        },
707        // select the given flag, update the placeholder and the active list item
708        // Note: called from _setInitialState, _updateFlagFromNumber, _selectListItem, setCountry
709        _setFlag: function(countryCode) {
710            var prevCountry = this.selectedCountryData && this.selectedCountryData.iso2 ? this.selectedCountryData : {};
711            // do this first as it will throw an error and stop if c
711ountryCode is invalid
712            this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {};
713            // update the defaultCountry - we only need the iso2 from now on, so just store that
714            if (this.selectedCountryData.iso2) {
715                this.defaultCountry = this.selectedCountryData.iso2;
716            }
717            this.selectedFlagInner.attr("class", "iti-flag " + countryCode);
718            // update the selected country's title attribute
719            var title = countryCode ? this.selectedCountryData.name + ": +" + this.selectedCountryData.dialCode : "Unknown";
720            this.selectedFlagInner.parent().attr("title", title);
721            if (this.options.separateDialCode) {
722                var dialCode = this.selectedCountryData.dialCode ? "+" + this.selectedCountryData.dialCode : "", parent = this.telInput.parent();
723                if (prevCountry.dialCode) {
724                    parent.removeClass("iti-sdc-" + (prevCountry.dialCode.length + 1));
725                }
726                if (dialCode) {
727                    parent.addClass("iti-sdc-" + dialCode.length);
728                }
729                this.selectedDialCode.text(dialCode);
730            }
731            // and the input's placeholder
732            this._updatePlaceholder();
733            // update the active list item
734            this.countryListItems.removeClass("active");
735            if (countryCode) {
736                this.countryListItems.find(".iti-flag." + countryCode).first().closest(".country").addClass("active");
737            }
738            // return if the flag has changed or not
739            return prevCountry.iso2 !== countryCode;
740        },
741        // update the input placeholder to an example number from the currently selected country
742        _updatePlaceholder: function() {
743            var shouldSetPlaceholder = this.options.autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && (this.options.autoPlaceholder === true || this.options.autoPlaceholder === "polite");
744            if (window.intlTelInputUtils && shouldSetPlaceholder && this.selectedCountryData) {
745                var numberType = intlTelInputUtils.numberType[this.options.placeholderNumberType], placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, this.options.nationalMode, numberType) : "";
746                placeholder = this._beforeSetNumber(placeholder);
747                if (typeof this.options.customPlaceholder === "function") {
748                    placeholder = this.options.customPlaceholder(placeholder, this.selectedCountryData);
749                }
750                this.telInput.attr("placeholder", placeholder);
751            }
752        },
753        // called when the user selects a list item from the dropdown
754        _selectListItem: function(listItem) {
755            // update selected flag and active list item
756            var flagChanged = this._setFlag(listItem.attr("data-country-code"));
757            this._closeDropdown();
758            this._updateDialCode(listItem.attr("data-dial-code"), true);
759            // focus the input
760            this.telInput.focus();
761            // put cursor at end - this fix is required for FF and IE11 (with nationalMode=false i.e. auto inserting dial code), who try to put the cursor at the beginning the first time
762            if (this.isGoodBrowser) {
763                var len = this.telInput.val().length;
764                this.telInput[0].setSelectionRange(len, len);
765            }
766            if (flagChanged) {
767                this._triggerCountryChange();
768            }
769        },
770        // close the dropdown and unbind any listeners
771        _closeDropdown: function() {
772            this.countryList.addClass("hide");
773            // update the arrow
774            this.selectedFlagInner.children(".iti-arrow").removeClass("up");
775            // unbind key events
776            $(document).off(this.ns);
777            // unbind click-off-to-close
778            $("html").off(this.ns);
779            // unbind hover and click listeners
780            this.countryList.off(this.ns);
781            // remove menu from container
782            if (this.options.dropdownContainer) {
783                if (!this.isMobile) {
784                    $(window).off("scroll" + this.ns);
785                }
786                this.dropdown.detach();
787            }
788        },
789        // check if an element is visible within it's container, else scroll until it is
790        _scrollTo: function(element, middle) {
791            var container = this.countryList, containerHeight = container.height(), containerTop = container.offset().top, containerBottom = containerTop + containerHeight, elementHeight = element.outerHeight(), elementTop = element.offset().top, elementBottom = elementTop + elementHeight, newScrollTop = elementTop - containerTop + container.scrollTop(), middleOffset = containerHeight / 2 - elementHeight / 2;
792            if (elementTop < containerTop) {
793                // scroll up
794                if (middle) {
795                    newScrollTop -= middleOffset;
796                }
797                container.scrollTop(newScrollTop);
798            } else if (elementBottom > containerBottom) {
799                // scroll down
800                if (middle) {
801                    newScrollTop += middleOffset;
802                }
803                var heightDifference = containerHeight - elementHeight;
804                container.scrollTop(newScrollTop - heightDifference);
805            }
806        },
807        // replace any existing dial code with the new one
808        // Note: called from _selectListItem and setCountry
809        _updateDialCode: function(newDialCode, hasSelectedListItem) {
810            var inputVal = this.telInput.val(), newNumber;
811            // save having to pass this every time
812            newDialCode = "+" + newDialCode;
813            if (inputVal.charAt(0) == "+") {
814                // there's a plus so we're dealing with a replacement (doesn't matter if nationalMode or not)
815                var prevDialCode = this._getDialCode(inputVal);
816                if (prevDialCode) {
817                    // current number contains a valid dial code, so replace it
818                    newNumber = inputVal.replace(prevDialCode, newDialCode);
819                } else {
820                    // current number contains an invalid dial code, so ditch it
821                    // (no way to determine where the invalid dial code ends and the rest of the number begins)
822                    newNumber = newDialCode;
823                }
824            } else if (this.options.nationalMode || this.options.separateDialCode) {
825                // don't do anything
826                return;
827            } else {
828                // nationalMode is disabled
829                if (inputVal) {
830                    // there is an existing value with no dial code: prefix the new dial code
831                    newNumber = newDialCode + inputVal;
832                } else if (hasSelectedListItem || !this.options.autoHideDialCode) {
833                    // no existing value and either they've just selected a list item, or autoHideDialCode is disabled: insert new dial code
834                    newNumber = newDialCode;
835                } else {
836                    return;
837                }
838            }
839            this.telInput.val(newNumber);
840        },
841        // try and extract a valid international dial code from a full telephone number
842        // Note: returns the raw string inc plus character and any whitespace/dots etc
843        _getDialCode: function(number) {
844            var dialCode = "";
845            // only interested in international numbers (starting with a plus)
846            if (number.charAt(0) == "+") {
847                var numericChars = "";
848                // iterate over chars
849                for (var i = 0; i < number.length; i++) {
850                    var c = number.charAt(i);
851                    // if char is number
852                    if ($.isNumeric(c)) {
853                        numericChars += c;
854                        // if current numericChars make a valid dial code
855                        if (this.countryCodes[numericChars]) {
856                            // store the actual raw string (useful for matching later)
857                            dialCode = number.substr(0, i + 1);
858                        }
859                        // longest dial code is 4 chars
860                        if (numericChars.length == 4) {
861                            break;
862                        }
863                    }
864                }
865            }
866            return dialCode;
867        },
868        // get the input val, adding the dial code if separateDialCode is enabled
869        _getFullNumber: function() {
870            var val = this.telInput.val(), dialCode = this.selectedCountryData.dialCode, prefix;
871            if (this.options.separateDialCode) {
872                prefix = "+" + dialCode;
873            } else if (dialCode && dialCode.charAt(0) == "1" && dialCode.length == 4 && dialCode.substr(1) != val.substr(0, 3)) {
874                // if we're dealing with a NANP country, ensure the number includes the area code
875                prefix = dialCode.substr(1);
876            } else {
877                prefix = "";
878            }
879            return prefix + val;
880        },
881        // remove the dial code if separateDialCode is enabled
882        _beforeSetNumber: function(number) {
883            if (this.options.separateDialCode) {
884                var dialCode = this._getDialCode(number);
885                if (dialCode) {
886                    // US dialCode is "+1", which is what we want
887                    // CA dialCode is "+1 123", which is wrong - should be "+1" (as it has multiple area codes)
888                    // AS dialCode is "+1 684", which is what we want
889                    // Solution: if the country has area codes, then revert to just the dial code
890                    if (this.selectedCountryData.areaCodes !== null) {
891                        dialCode = "+" + this.selectedCountryData.dialCode;
892                    }
893                    // a lot of numbers will have a space separating the dial code and the main number, and some NANP numbers will have a hyphen e.g. +1 684-733-1234 - in both cases we want to get rid of it
894                    // NOTE: don't just trim all non-numerics as may want to preserve an open parenthesis etc
895                    var start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
896                    number = number.substr(start);
897                }
898            }
899            return this._cap(number);
900        },
901        // trigger the 'countrychange' event
902        _triggerCountryChange: function() {
903            this.telInput.trigger("countrychange", this.selectedCountryData);
904        },
905        /**************************
906   *  SECRET PUBLIC METHODS
907   **************************/
908        // this is called when the geoip call returns
909        handleAutoCountry: function() {
910            if (this.options.initialCountry === "auto") {
911                // we must set this even if there is an initial val in the input: in case the initial val is invali
911d and they delete it - they should see their auto country
912                this.defaultCountry = $.fn[pluginName].autoCountry;
913                // if there's no initial value in the input, then update the flag
914                if (!this.telInput.val()) {
915                    this.setCountry(this.defaultCountry);
916                }
917                this.autoCountryDeferred.resolve();
918            }
919        },
920        // this is called when the utils request completes
921        handleUtils: function() {
922            // if the request was successful
923            if (window.intlTelInputUtils) {
924                // if there's an initial value in the input, then format it
925                if (this.telInput.val()) {
926                    this._updateValFromNumber(this.telInput.val());
927                }
928                this._updatePlaceholder();
929            }
930            this.utilsScriptDeferred.resolve();
931        },
932        /********************
933   *  PUBLIC METHODS
934   ********************/
935        // remove plugin
936        destroy: function() {
937            if (this.allowDropdown) {
938                // make sure the dropdown is closed (and unbind listeners)
939                this._closeDropdown();
940                // click event to open dropdown
941                this.selectedFlagInner.parent().off(this.ns);
942                // label click hack
943                this.telInput.closest("label").off(this.ns);
944            }
945            // unbind submit event handler on form
946            if (this.options.autoHideDialCode) {
947                var form = this.telInput.prop("form");
948                if (form) {
949                    $(form).off(this.ns);
950                }
951            }
952            // unbind all events: key events, and focus/blur events if autoHideDialCode=true
953            this.telInput.off(this.ns);
954            // remove markup (but leave the original input)
955            var container = this.telInput.parent();
956            container.before(this.telInput).remove();
957        },
958        // get the extension from the current number
959        getExtension: function() {
960            if (window.intlTelInputUtils) {
961                return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2);
962            }
963            return "";
964        },
965        // format the number to the given format
966        getNumber: function(format) {
967            if (window.intlTelInputUtils) {
968                return intlTelInputUtils.formatNumber(this._getFullNumber(), this.selectedCountryData.iso2, format);
969            }
970            return "";
971        },
972        // get the type of the entered number e.g. landline/mobile
973        getNumberType: function() {
974            if (window.intlTelInputUtils) {
975                return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2);
976            }
977            return -99;
978        },
979        // get the country data for the currently selected flag
980        getSelectedCountryData: function() {
981            // if this is undefined, the plugin will return it's instance instead, so in that case an empty object makes more sense
982            return this.selectedCountryData || {};
983        },
984        // get the validation error
985        getValidationError: function() {
986            if (window.intlTelInputUtils) {
987                return intlTelInputUtils.getValidationError(this._getFullNumber(), this.selectedCountryData.iso2);
988            }
989            return -99;
990        },
991        // validate the input val - assumes the global function isValidNumber (from utilsScript)
992        isValidNumber: function() {
993            var val = $.trim(this._getFullNumber()), countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : "";
994            return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null;
995        },
996        // update the selected flag, and update the input val accordingly
997        setCountry: function(countryCode) {
998            countryCode = countryCode.toLowerCase();
999            // check if already selected
1000            if (!this.selectedFlagInner.hasClass(countryCode)) {
1001                this._setFlag(countryCode);
1002                this._updateDialCode(this.selectedCountryData.dialCode, false);
1003                this._triggerCountryChange();
1004            }
1005        },
1006        // set the input value and update the flag
1007        setNumber: function(number) {
1008            // we must update the flag first, which updates this.selectedCountryData, which is used for formatting the number before displaying it
1009            var flagChanged = this._updateFlagFromNumber(number);
1010            this._updateValFromNumber(number);
1011            if (flagChanged) {
1012                this._triggerCountryChange();
1013            }
1014        }
1015    };
1016    // using https://github.com/jquery-boilerplate/jquery-boilerplate/wiki/Extending-jQuery-Boilerplate
1017    // (adapted to allow public functions)
1018    $.fn[pluginName] = function(options) {
1019        var args = arguments;
1020        // Is the first parameter an object (options), or was omitted,
1021        // instantiate a new instance of the plugin.
1022        if (options === undefined || typeof options === "object") {
1023            // collect all of the deferred objects for all instances created with this selector
1024            var deferreds = [];
1025            this.each(function() {
1026                if (!$.data(this, "plugin_" + pluginName)) {
1027                    var instance = new Plugin(this, options);
1028                    var instanceDeferreds = instance._init();
1029                    // we now have 2 deffereds: 1 for auto country, 1 for utils script
1030                    deferreds.push(instanceDeferreds[0]);
1031                    deferreds.push(instanceDeferreds[1]);
1032                    $.data(this, "plugin_" + pluginName, instance);
1033                }
1034            });
1035            // return the promise from the "master" deferred object that tracks all the others
1036            return $.when.apply(null, deferreds);
1037        } else if (typeof options === "string" && options[0] !== "_") {
1038            // If the first parameter is a string and it doesn't start
1039            // with an underscore or "contains" the `init`-function,
1040            // treat this as a call to a public method.
1041            // Cache the method call to make it possible to return a value
1042            var returns;
1043            this.each(function() {
1044                var instance = $.data(this, "plugin_" + pluginName);
1045                // Tests that there's already a plugin-instance
1046                // and checks that the requested public method exists
1047                if (instance instanceof Plugin && typeof instance[options] === "function") {
1048                    // Call the method of our plugin instance,
1049                    // and pass it the supplied arguments.
1050                    returns = instance[options].apply(instance, Array.prototype.slice.call(args, 1));
1051                }
1052                // Allow instances to be destroyed via the 'destroy' method
1053                if (options === "destroy") {
1054                    $.data(this, "plugin_" + pluginName, null);
1055                }
1056            });
1057            // If the earlier cached method gives a value back return the value,
1058            // otherwise return this to preserve chainability.
1059            return returns !== undefined ? returns : this;
1060        }
1061    };
1062    /********************
1063 *  STATIC METHODS
1064 ********************/
1065    // get the country data object
1066    $.fn[pluginName].getCountryData = function() {
1067        return allCountries;
1068    };
1069    // load the utils script
1070    $.fn[pluginName].loadUtils = function(path, utilsScriptDeferred) {
1071        if (!$.fn[pluginName].loadedUtilsScript) {
1072            // don't do this twice! (dont just check if window.intlTelInputUtils exists as if init plugin multiple times in quick succession, it may not have finished loading yet)
1073            $.fn[pluginName].loadedUtilsScript = true;
1074            // dont use $.getScript as it prevents caching
1075            $.ajax({
1076                type: "GET",
1077                url: path,
1078                complete: function() {
1079                    // tell all instances that the utils request is complete
1080                    $(".intl-tel-input input").intlTelInput("handleUtils");
1081                },
1082                dataType: "script",
1083                cache: true
1084            });
1085        } else if (utilsScriptDeferred) {
1086            utilsScriptDeferred.resolve();
1087        }
1088    };
1089    // version
1090    $.fn[pluginName].version = "10.0.2";
1091    // default options
1092    $.fn[pluginName].defaults = defaults;
1093    // Array of country objects for the flag dropdown.
1094    // Here is the criteria for the plugin to support a given country/territory
1095    // - It has an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
1096    // - It has a country calling code: https://en.wikipedia.org/wiki/List_of_country_calling_codes
1097    // - It has a flag in the region-flags project: https://github.com/behdad/region-flags/tree/gh-pages/png
1098    // - It is supported by libphonenumber (it must be listed here): https://github.com/googlei18n/libphonenumber/blob/master/resources/ShortNumberMetadata.xml
1099    // Each country array has the following information:
1100    // [
1101    //    Country name,
1102    //    iso2 code,
1103    //    International dial code,
1104    //    Order (if >1 country with same dial code),
1105    //    Area codes
1106    // ]
1107    var allCountries = [ [ "Afghanistan (‫افغانستان‬‎)", "af", "93" ], [ "Albania (Shqipëri)", "al", "355" ], [ "Algeria (‫الجزائر‬‎)", "dz", "213" ], [ "American Samoa", "as", "1684" ], [ "Andorra", "ad", "376" ], [ "Angola", "ao", "244" ], [ "Anguilla", "ai", "1264" ], [ "Antigua and Barbuda", "ag", "1268" ], [ "Argentina", "ar", "54" ], [ "Armenia (Հայաստան)", "am", "374" ], [ "Aruba", "aw", "297" ], [ "Australia", "au", "61", 0 ], [ "Austria (Österreich)", "at", "43" ], [ "Azerbaijan (Azərbaycan)", "az", "994" ], [ "Bahamas", "bs", "1242" ], [ "Bahrain (‫البحرين‬‎)", "bh", "973" ], [ "Bangladesh (বাংলাদেশ)", "bd", "880" ], [ "Barbados", "bb", "1246" ], [ "Belarus (Беларусь)", "by", "375" ], [ "Belgium (België)", "be", "32" ], [ "Belize", "bz", "501" ], [ "Benin (Bénin)", "bj", "229" ], [ "Bermuda", "bm", "1441" ], [ "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", "1284" ], [ "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 ], [ "Cayman Islands", "ky", "1345" ], [ "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", "1767" ], [ "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
1107aat)", "gl", "299" ], [ "Grenada", "gd", "1473" ], [ "Guadeloupe", "gp", "590", 0 ], [ "Guam", "gu", "1671" ], [ "Guatemala", "gt", "502" ], [ "Guernsey", "gg", "44", 1 ], [ "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 ], [ "Israel (‫ישראל‬‎)", "il", "972" ], [ "Italy (Italia)", "it", "39", 0 ], [ "Jamaica", "jm", "1876" ], [ "Japan (日本)", "jp", "81" ], [ "Jersey", "je", "44", 3 ], [ "Jordan (‫الأردن‬‎)", "jo", "962" ], [ "Kazakhstan (Казахстан)", "kz", "7", 1 ], [ "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 ], [ "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", "1664" ], [ "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", "1670" ], [ "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 (Saint-Barthélemy)", "bl", "590", 1 ], [ "Saint Helena", "sh", "290" ], [ "Saint Kitts and Nevis", "kn", "1869" ], [ "Saint Lucia", "lc", "1758" ], [ "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", "1784" ], [ "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", "1721" ], [ "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 ], [ "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", "1868" ], [ "Tunisia (‫تونس‬‎)", "tn", "216" ], [ "Turkey (Türkiye)", "tr", "90" ], [ "Turkmenistan", "tm", "993" ], [ "Turks and Caicos Islands", "tc", "1649" ], [ "Tuvalu", "tv", "688" ], [ "U.S. Virgin Islands", "vi", "1340" ], [ "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 ], [ "Venezuela", "ve", "58" ], [ "Vietnam (Việt Nam)", "vn", "84" ], [ "Wallis and Futuna", "wf", "681" ], [ "Western Sahara (‫الصحراء الغربية‬‎)", "eh", "212", 1 ], [ "Yemen (‫اليمن‬‎)", "ye", "967" ], [ "Zambia", "zm", "260" ], [ "Zimbabwe", "zw", "263" ], [ "Åland Islands", "ax", "358", 1 ] ];
1108    // loop over all of the countries above
1109    for (var i = 0; i < allCountries.length; i++) {
1110        var c = allCountries[i];
1111        allCountries[i] = {
1112            name: c[0],
1113            iso2: c[1],
1114            dialCode: c[2],
1115            priority: c[3] || 0,
1116            areaCodes: c[4] || null
1117        };
1118    }
1119});

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.