PageSourceSearch

https://onlineservices.nakheel.com/Assets/IntPhone/js/intlTelInput.js?v=639089958405992272

js nakheel.com collected 2026-10-02 04:48:32 UTC 68,752 bytes, 1,122 lines download raw bytes

1/*
2 * International Telephone Input v8.5.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 or remove input placeholder with an example number for the selected country
27        autoPlaceholder: true,
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
35        formatOnInit: true,
36        // geoIp lookup function
37        geoIpLookup: null,
38        // initial country
39        initialCountry: "",
40        // don't insert international dial codes
41        nationalMode: true,
42        // number type to use for placeholders
43        numberType: "MOBILE",
44        // display only these countries
45        onlyCountries: [],
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    };
63    // keep track of if the window.load event has fired as impossible to check after the fact
64    $(window).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                // let's force this for now for simplicity - we can support this later if need be
87                this.options.allowDropdown = true;
88            }
89            // we cannot just test screen size as some smartphones/website meta tags will report desktop resolutions
90            // Note: for some reason jasmine breaks if you put this in the main Plugin function with the rest of these declarations
91            // Note: to target Android Mobiles (and not Tablets), we must find "Android" and "Mobile"
92            this.isMobile = /Android.+Mobile|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
93            if (this.isMobile) {
94                // trigger the mobile dropdown css
95                $("body").addClass("iti-mobile");
96                // on mobile, we want a full screen dropdown, so we must append it to the body
97                if (!this.options.dropdownContainer) {
98                    this.options.dropdownContainer = "body";
99                }
100            }
101            // we return these deferred objects from the _init() call so they can be watched, and then we resolve them when each specific request returns
102            // Note: again, jasmine breaks when I put these in the Plugin function
103            this.autoCountryDeferred = new $.Deferred();
104            this.utilsScriptDeferred = new $.Deferred();
105            // process all the data: onlyCountries, excludeCountries, preferredCountries etc
106            this._processCountryData();
107            // generate the markup
108            this._generateMarkup();
109            // set the initial state of the input value and the selected flag
110            this._setInitialState();
111            // start all of the event listeners: autoHideDialCode, input keydown, selectedFlag click
112            this._initListeners();
113            // utils script, and auto country
114            this._initRequests();
115            // return the deferreds
116            return [ this.autoCountryDeferred, this.utilsScriptDeferred ];
117        },
118        /********************
119   *  PRIVATE METHODS
120   ********************/
121        // prepare all of the country data, including onlyCountries, excludeCountries and preferredCountries options
122        _processCountryData: function() {
123            // process onlyCountries or excludeCountries array if present
124            this._processAllCountries();
125            // process the countryCodes map
126            this._processCountryCodes();
127            // process the preferredCountries
128            this._processPreferredCountries();
129        },
130        // add a country code to this.countryCodes
131        _addCountryCode: function(iso2, dialCode, priority) {
132            if (!(dialCode in this.countryCodes)) {
133                this.countryCodes[dialCode] = [];
134            }
135            var index = priority || 0;
136            this.countryCodes[dialCode][index] = iso2;
137        },
138        // filter the given countries using the process function
139        _filterCountries: function(countryArray, processFunc) {
140            var i;
141            // standardise case
142            for (i = 0; i < countryArray.length; i++) {
143                countryArray[i] = countryArray[i].toLowerCase();
144            }
145            // build instance country array
146            this.countries = [];
147            for (i = 0; i < allCountries.length; i++) {
148                if (processFunc($.inArray(allCountries[i].iso2, countryArray))) {
149                    this.countries.push(allCountries[i]);
150                }
151            }
152        },
153        // process onlyCountries or excludeCountries array if present
154        _processAllCountries: function() {
155            if (this.options.onlyCountries.length) {
156                // process onlyCountries option
157                this._filterCountries(this.options.onlyCountries, function(inArray) {
158                    // if country is in array
159                    return inArray != -1;
160                });
161            } else if (this.options.excludeCountries.length) {
162                // process excludeCountries option
163                this._filterCountries(this.options.excludeCountries, function(inArray) {
164                    // if country is not in array
165                    return inArray == -1;
166                });
167            } else {
168                this.countries = allCountries;
169            }
170        },
171        // process the countryCodes map
172        _processCountryCodes: function() {
173            this.countryCodes = {};
174            for (var i = 0; i < this.countries.length; i++) {
175                var c = this.countries[i];
176                this._addCountryCode(c.iso2, c.dialCode, c.priority);
177                // area codes
178                if (c.areaCodes) {
179                    for (var j = 0; j < c.areaCodes.length; j++) {
180                        // full dial code is country code + dial code
181                        this._addCountryCode(c.iso2, c.dialCode + c.areaCodes[j]);
182                    }
183                }
184            }
185        },
186        // process preferred countries - iterate through the preferences, fetching the country data for each one
187        _processPreferredCountries: function() {
188            this.preferredCountries = [];
189            for (var i = 0; i < this.options.preferredCountries.length; i++) {
190                var countryCode = this.options.preferredCountries[i].toLowerCase(), countryData = this._getCountryData(countryCode, false, true);
191                if (countryData) {
192                    this.preferredCountries.push(countryData);
193                }
194            }
195        },
196        // generate all of the markup for the plugin: the selected flag overlay, and the dropdown
197        _generateMarkup: function() {
198            // 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 c
198ould mean the wrong number is saved (esp in nationalMode)
199            this.telInput.attr("autocomplete", "off");
200            // containers (mostly for positioning)
201            var parentClass = "intl-tel-input";
202            if (this.options.allowDropdown) {
203                parentClass += " allow-dropdown";
204            }
205            if (this.options.separateDialCode) {
206                parentClass += " separate-dial-code";
207            }
208            this.telInput.wrap($("<div>", {
209                "class": parentClass
210            }));
211            this.flagsContainer = $("<div>", {
212                "class": "flag-container"
213            }).insertBefore(this.telInput);
214            // currently selected flag (displayed to left of input)
215            var selectedFlag = $("<div>", {
216                "class": "selected-flag"
217            });
218            selectedFlag.appendTo(this.flagsContainer);
219            this.selectedFlagInner = $("<div>", {
220                "class": "iti-flag"
221            }).appendTo(selectedFlag);
222            if (this.options.separateDialCode) {
223                this.selectedDialCode = $("<div>", {
224                    "class": "selected-dial-code"
225                }).appendTo(selectedFlag);
226            }
227            if (this.options.allowDropdown) {
228                // make element focusable and tab naviagable
229                selectedFlag.attr("tabindex", "0");
230                // CSS triangle
231                $("<div>", {
232                    "class": "iti-arrow"
233                }).appendTo(selectedFlag);
234                // country dropdown: preferred countries, then divider, then all countries
235                this.countryList = $("<ul>", {
236                    "class": "country-list hide"
237                });
238                if (this.preferredCountries.length) {
239                    this._appendListItems(this.preferredCountries, "preferred");
240                    $("<li>", {
241                        "class": "divider"
242                    }).appendTo(this.countryList);
243                }
244                this._appendListItems(this.countries, "");
245                // this is useful in lots of places
246                this.countryListItems = this.countryList.children(".country");
247                // create dropdownContainer markup
248                if (this.options.dropdownContainer) {
249                    this.dropdown = $("<div>", {
250                        "class": "intl-tel-input iti-container"
251                    }).append(this.countryList);
252                } else {
253                    this.countryList.appendTo(this.flagsContainer);
254                }
255            } else {
256                // a little hack so we don't break anything
257                this.countryListItems = $();
258            }
259        },
260        // add a country <li> to the countryList <ul> container
261        _appendListItems: function(countries, className) {
262            // we create so many DOM elements, it is faster to build a temp string
263            // and then add everything to the DOM in one go at the end
264            var tmp = "";
265            // for each country
266            for (var i = 0; i < countries.length; i++) {
267                var c = countries[i];
268                // open the list item
269                tmp += "<li class='country " + className + "' data-dial-code='" + c.dialCode + "' data-country-code='" + c.iso2 + "'>";
270                // add the flag
271                tmp += "<div class='flag-box'><div class='iti-flag " + c.iso2 + "'></div></div>";
272                // and the country name and dial code
273                tmp += "<span class='country-name'>" + c.name + "</span>";
274                tmp += "<span class='dial-code'>+" + c.dialCode + "</span>";
275                // close the list item
276                tmp += "</li>";
277            }
278            this.countryList.append(tmp);
279        },
280        // set the initial state of the input value and the selected flag by:
281        // 1. extracting a dial code from the given number
282        // 2. using explicit initialCountry
283        // 3. picking the first preferred country
284        // 4. picking the first country
285        _setInitialState: function() {
286            var val = this.telInput.val();
287            // if we already have a dial code we can go ahead and set the flag, else fall back to default
288            if (this._getDialCode(val)) {
289                this._updateFlagFromNumber(val, true);
290            } else if (this.options.initialCountry !== "auto") {
291                // see if we should select a flag
292                if (this.options.initialCountry) {
293                    this._setFlag(this.options.initialCountry, true);
294                } else {
295                    // no dial code and no initialCountry, so default to first in list
296                    this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2;
297                    if (!val) {
298                        this._setFlag(this.defaultCountry, true);
299                    }
300                }
301                // if empty and no nationalMode and no autoHideDialCode then insert the default dial code
302                if (!val && !this.options.nationalMode && !this.options.autoHideDialCode && !this.options.separateDialCode) {
303                    this.telInput.val("+" + this.selectedCountryData.dialCode);
304                }
305            }
306            // NOTE: if initialCountry is set to auto, that will be handled separately
307            // format
308            if (val) {
309                // this wont be run after _updateDialCode as that's only called if no val
310                this._updateValFromNumber(val, this.options.formatOnInit);
311            }
312        },
313        // initialise the main event listeners: input keyup, and click selected flag
314        _initListeners: function() {
315            this._initKeyListeners();
316            if (this.options.autoHideDialCode) {
317                this._initFocusListeners();
318            }
319            if (this.options.allowDropdown) {
320                this._initDropdownListeners();
321            }
322        },
323        // initialise the dropdown listeners
324        _initDropdownListeners: function() {
325            var that = this;
326            // 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
327            var label = this.telInput.closest("label");
328            if (label.length) {
329                label.on("click" + this.ns, function(e) {
330                    // if the dropdown is closed, then focus the input, else ignore the click
331                    if (that.countryList.hasClass("hide")) {
332                        that.telInput.focus();
333                    } else {
334                        e.preventDefault();
335                    }
336                });
337            }
338            // toggle country dropdown on click
339            var selectedFlag = this.selectedFlagInner.parent();
340            selectedFlag.on("click" + this.ns, function(e) {
341                // only intercept this event if we're opening the dropdown
342                // else let it bubble up to the top ("click-off-to-close" listener)
343                // we cannot just stopPropagation as it may be needed to close another instance
344                if (that.countryList.hasClass("hide") && !that.telInput.prop("disabled") && !that.telInput.prop("readonly")) {
345                    that._showDropdown();
346                }
347            });
348            // open dropdown list if currently focused
349            this.flagsContainer.on("keydown" + that.ns, function(e) {
350                var isDropdownHidden = that.countryList.hasClass("hide");
351                if (isDropdownHidden && (e.which == keys.UP || e.which == keys.DOWN || e.which == keys.SPACE || e.which == keys.ENTER)) {
352                    // prevent form from being submitted if "ENTER" was pressed
353                    e.preventDefault();
354                    // prevent event from being handled again by document
355                    e.stopPropagation();
356                    that._showDropdown();
357                }
358                // allow navigation from dropdown to input on TAB
359                if (e.which == keys.TAB) {
360                    that._closeDropdown();
361                }
362            });
363        },
364        // init many requests: utils script / geo ip lookup
365        _initRequests: function() {
366            var that = this;
367            // if the user has specified the path to the utils script, fetch it on window.load, else resolve
368            if (this.options.utilsScript) {
369                // if the plugin is being initialised after the window.load event has already been fired
370                if ($.fn[pluginName].windowLoaded) {
371                    $.fn[pluginName].loadUtils(this.options.utilsScript, this.utilsScriptDeferred);
372                } else {
373                    // wait until the load event so we don't block any other requests e.g. the flags image
374                    $(window).load(function() {
375                        $.fn[pluginName].loadUtils(that.options.utilsScript, that.utilsScriptDeferred);
376                    });
377                }
378            } else {
379                this.utilsScriptDeferred.resolve();
380            }
381            if (this.options.initialCountry === "auto") {
382                this._loadAutoCountry();
383            } else {
384                this.autoCountryDeferred.resolve();
385            }
386        },
387        // perform the geo ip lookup
388        _loadAutoCountry: function() {
389            var that = this;
390            // check for cookie
391            var cookieAutoCountry = window.Cookies ? Cookies.get("itiAutoCountry") : "";
392            if (cookieAutoCountry) {
393                $.fn[pluginName].autoCountry = cookieAutoCountry;
394            }
395            // 3 options:
396            // 1) already loaded (we're done)
397            // 2) not already started loading (start)
398            // 3) already started loading (do nothing - just wait for loading callback to fire)
399            if ($.fn[pluginName].autoCountry) {
400                this.handleAutoCountry();
401            } else if (!$.fn[pluginName].startedLoadingAutoCountry) {
402                // don't do this twice!
403                $.fn[pluginName].startedLoadingAutoCountry = true;
404                if (typeof this.options.geoIpLookup === "function") {
405                    this.options.geoIpLookup(function(countryCode) {
406                        $.fn[pluginName].autoCountry = countryCode.toLowerCase();
407                        if (window.Cookies) {
408                            Cookies.set("itiAutoCountry", $.fn[pluginName].autoCountry, {
409                                path: "/"
410                            });
411                        }
412                        // tell all instances the auto country is ready
413                        // TODO: this should just be the current instances
414                        // 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.
415                        setTimeout(function() {
416                            $(".intl-tel-input input").intlTelInput("handleAutoCountry");
417                        });
418                    });
419                }
420            }
421        },
422        // initialize any key listeners
423        _initKeyListeners: function() {
424            var that = this;
425            // update flag on keyup
426            // (keep this listener separate otherwise the setTimeout breaks all the tests)
427            this.telInput.on("keyup" + this.ns, function() {
428                that._updateFlagFromNumber(that.telInput.val());
429            });
430            // update flag on cut/paste events (now supported in all major browsers)
431            this.telInput.on("cut" + this.ns + " paste" + this.ns + " keyup" + this.ns, function() {
432                // hack because "paste" event is fired before input is updated
433                setTimeout(function() {
434                    that._updateFlagFromNumber(that.telInput.val());
435                });
436            });
437        },
438        // adhere to the input's maxlength attr
439        _cap: function(number) {
440            var max = this.telInput.attr("maxlength");
441            return max && number.length > max ? number.substr(0, max) : number;
442        },
443        // listen for mousedown, focus and blur
444        _initFocusListeners: function() {
445            var that = this;
446            // 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
447            this.telInput.on("mousedown" + this.ns, function(e) {
448                if (!that.telInput.is(":focus") && !that.telInput.val()) {
449                    e.preventDefault();
450                    // but this also cancels the focus, so we must trigger that manually
451                    that.telInput.focus();
452                }
453            });
454            // on focus: if empty, insert the dial code for the currently selected flag
455            this.telInput.on("focus" + this.ns, function(e) {
456                if (!that.telInput.val() && !that.telInput.prop("readonly") && that.selectedCountryData.dialCode) {
457                    // insert the dial code
458                    that.telInput.val("+" + that.selectedCountryData.dialCode);
459                    // 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
460                    that.telInput.one("keypress.plus" + that.ns, function(e) {
461                        if (e.which == keys.PLUS) {
462                            that.telInput.val("");
463                        }
464                    });
465                    // 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
466                    setTimeout(function() {
467                        var input = that.telInput[0];
468                        if (that.isGoodBrowser) {
469                            var len = that.telInput.val().length;
470                            input.setSelectionRange(len, len);
471                        }
472                    });
473                }
474            });
475            // on blur or form submit: if just a dial code then remove it
476            var form = this.telInput.prop("form");
477            if (form) {
478                $(form).on("submit" + this.ns, function() {
479                    that._removeEmptyDialCode();
480                });
481            }
482            this.telInput.on("blur" + this.ns, function() {
483                that._removeEmptyDialCode();
484            });
485        },
486        _removeEmptyDialCode: function() {
487            var value = this.telInput.val(), startsPlus = value.charAt(0) == "+";
488            if (startsPlus) {
489                var numeric = this._getNumeric(value);
490                // if just a plus, or if just a dial code
491                if (!numeric || this.selectedCountryData.dialCode == numeric) {
492                    this.telInput.val("");
493                }
494            }
495            // remove the keypress listener we added on focus
496            this.telInput.off("keypress.plus" + this.ns);
497        },
498        // extract the numeric digits from the given string
499        _getNumeric: function(s) {
500            return s.replace(/\D/g, "");
501        },
502        // show the dropdown
503        _showDropdown: function() {
504            this._setDropdownPosition();
505            // update highlighting and scroll to active list item
506            var activeListItem = this.countryList.children(".active");
507            if (activeListItem.length) {
508                this._highlightListItem(activeListItem);
509                this._scrollTo(activeListItem);
510            }
511            // bind all the dropdown-related listeners: mouseover, click, click-off, keydown
512            this._bindDropdownListeners();
513            // update the arrow
514            this.selectedFlagInner.children(".iti-arrow").addClass("up");
515        },
516        // decide where to position dropdown (depends on position within viewport, and scroll)
517        _setDropdownPosition: function() {
518            var that = this;
519            if (this.options.dropdownContainer) {
520                this.dropdown.appendTo(this.options.dropdownContainer);
521            }
522            // show the menu and grab the dropdown height
523            this.dropdownHeight = this.countryList.removeClass("hide").outerHeight();
524            if (!this.isMobile) {
525                var pos = this.telInput.offset(), inputTop = pos.top, windowTop = $(window).scrollTop(), // dropdownFitsBelow = (dropdownBottom < windowBottom)
526                dropdownFitsBelow = inputTop + this.telInput.outerHeight() + this.dropdownHeight < windowTop + $(window).height(), dropdownFitsAbove = inputTop - this.dropdownHeight > windowTop;
527                // by default, the dropdown will be below the input. If we want to position it above the input, we add the dropup class.
528                this.countryList.toggleClass("dropup", !dropdownFitsBelow && dropdownFitsAbove);
529                // if dropdownContainer is enabled, calculate postion
530                if (this.options.dropdownContainer) {
531                    // 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.
532                    var extraTop = !dropdownFitsBelow && dropdownFitsAbove ? 0 : this.telInput.innerHeight();
533                    // calculate placement
534                    this.dropdown.css({
535                        top: inputTop + extraTop,
536                        left: pos.left
537                    });
538                    // close menu on window scroll
539                    $(window).on("scroll" + this.ns, function() {
540                        that._closeDropdown();
541                    });
542                }
543            }
544        },
545        // we only bind dropdown listeners when the dropdown is open
546        _bindDropdownListeners: function() {
547            var that = this;
548            // when mouse over a list item, just highlight that one
549            // we add the class "highlight", so if they hit "enter" we know which one to select
550            this.countryList.on("mouseover" + this.ns, ".country", function(e) {
551                that._highlightListItem($(this));
552            });
553            // listen for country selection
554            this.countryList.on("click" + this.ns, ".country", function(e) {
555                that._selectListItem($(this));
556            });
557            // click off to close
558            // (except when this initial opening click is bubbling up)
559            // we cannot just stopPropagation as it may be needed to close another instance
560            var isOpening = true;
561            $("html").on("click" + this.ns, function(e) {
562                if (!isOpening) {
563                    that._closeDropdown();
564                }
565                isOpening = false;
566            });
567            // listen for up/down scrolling, enter to select, or letters to jump to country name.
568            // use keydown as keypress doesn't fire for non-char keys and we want to catch if they
569            // just hit down and hold it to scroll down (no keyup event).
570            // listen on the document because that's where key events are triggered if no input has focus
571            var query = "", queryTimer = null;
572            $(document).on("keydown" + this.ns, function(e) {
573                // prevent down key from scrolling the whole page,
574                // and enter key from submitting a form etc
575                e.preventDefault();
576                if (e.which == keys.UP || e.which == keys.DOWN) {
577                    // up and down to navigate
578                    that._handleUpDownKey(e.which);
579                } else if (e.which == keys.ENTER) {
580                    // enter to select
581                    that._handleEnterKey();
582                } else if (e.which == keys.ESC) {
583                    // esc to close
584                    that._closeDropdown();
585                } else if (e.which >
585= keys.A && e.which <= keys.Z || e.which == keys.SPACE) {
586                    // upper case letters (note: keyup/keydown only return upper case letters)
587                    // jump to countries that start with the query string
588                    if (queryTimer) {
589                        clearTimeout(queryTimer);
590                    }
591                    query += String.fromCharCode(e.which);
592                    that._searchForCountry(query);
593                    // if the timer hits 1 second, reset the query
594                    queryTimer = setTimeout(function() {
595                        query = "";
596                    }, 1e3);
597                }
598            });
599        },
600        // highlight the next/prev item in the list (and ensure it is visible)
601        _handleUpDownKey: function(key) {
602            var current = this.countryList.children(".highlight").first();
603            var next = key == keys.UP ? current.prev() : current.next();
604            if (next.length) {
605                // skip the divider
606                if (next.hasClass("divider")) {
607                    next = key == keys.UP ? next.prev() : next.next();
608                }
609                this._highlightListItem(next);
610                this._scrollTo(next);
611            }
612        },
613        // select the currently highlighted item
614        _handleEnterKey: function() {
615            var currentCountry = this.countryList.children(".highlight").first();
616            if (currentCountry.length) {
617                this._selectListItem(currentCountry);
618            }
619        },
620        // find the first list item whose name starts with the query string
621        _searchForCountry: function(query) {
622            for (var i = 0; i < this.countries.length; i++) {
623                if (this._startsWith(this.countries[i].name, query)) {
624                    var listItem = this.countryList.children("[data-country-code=" + this.countries[i].iso2 + "]").not(".preferred");
625                    // update highlighting and scroll
626                    this._highlightListItem(listItem);
627                    this._scrollTo(listItem, true);
628                    break;
629                }
630            }
631        },
632        // check if (uppercase) string a starts with string b
633        _startsWith: function(a, b) {
634            return a.substr(0, b.length).toUpperCase() == b;
635        },
636        // update the input's value to the given val (format first if possible)
637        // NOTE: this is called from _setInitialState, handleUtils and setNumber
638        _updateValFromNumber: function(number, doFormat, format) {
639            if (doFormat && window.intlTelInputUtils && this.selectedCountryData) {
640                if (!$.isNumeric(format)) {
641                    format = !this.options.separateDialCode && (this.options.nationalMode || number.charAt(0) != "+") ? intlTelInputUtils.numberFormat.NATIONAL : intlTelInputUtils.numberFormat.INTERNATIONAL;
642                }
643                number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format);
644            }
645            number = this._beforeSetNumber(number);
646            this.telInput.val(number);
647        },
648        // check if need to select a new flag based on the given number
649        // Note: called from _setInitialState, keyup handler, setNumber
650        _updateFlagFromNumber: function(number, isInit) {
651            // 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
652            // 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
653            if (number && this.options.nationalMode && this.selectedCountryData && this.selectedCountryData.dialCode == "1" && number.charAt(0) != "+") {
654                if (number.charAt(0) != "1") {
655                    number = "1" + number;
656                }
657                number = "+" + number;
658            }
659            // try and extract valid dial code from input
660            var dialCode = this._getDialCode(number), countryCode = null;
661            if (dialCode) {
662                // check if one of the matching countries is already selected
663                var countryCodes = this.countryCodes[this._getNumeric(dialCode)], alreadySelected = this.selectedCountryData && $.inArray(this.selectedCountryData.iso2, countryCodes) != -1;
664                // if a matching country is not already selected (or this is an unknown NANP area code): choose the first in the list
665                if (!alreadySelected || this._isUnknownNanp(number, dialCode)) {
666                    // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first non-empty index
667                    for (var j = 0; j < countryCodes.length; j++) {
668                        if (countryCodes[j]) {
669                            countryCode = countryCodes[j];
670                            break;
671                        }
672                    }
673                }
674            } else if (number.charAt(0) == "+" && this._getNumeric(number).length) {
675                // invalid dial code, so empty
676                // Note: use getNumeric here because the number has not been formatted yet, so could contain bad chars
677                countryCode = "";
678            } else if (!number || number == "+") {
679                // empty, or just a plus, so default
680                countryCode = this.defaultCountry;
681            }
682            if (countryCode !== null) {
683                this._setFlag(countryCode, isInit);
684            }
685        },
686        // 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 +1 702) and the actual number's length is >=4
687        _isUnknownNanp: function(number, dialCode) {
688            return dialCode == "+1" && this._getNumeric(number).length >= 4;
689        },
690        // remove highlighting from other list items and highlight the given item
691        _highlightListItem: function(listItem) {
692            this.countryListItems.removeClass("highlight");
693            listItem.addClass("highlight");
694        },
695        // find the country data for the given country code
696        // the ignoreOnlyCountriesOption is only used during init() while parsing the onlyCountries array
697        _getCountryData: function(countryCode, ignoreOnlyCountriesOption, allowFail) {
698            var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries;
699            for (var i = 0; i < countryList.length; i++) {
700                if (countryList[i].iso2 == countryCode) {
701                    return countryList[i];
702                }
703            }
704            if (allowFail) {
705                return null;
706            } else {
707                throw new Error("No country data for '" + countryCode + "'");
708            }
709        },
710        // select the given flag, update the placeholder and the active list item
711        // Note: called from _setInitialState, _updateFlagFromNumber, _selectListItem, setCountry
712        _setFlag: function(countryCode, isInit) {
713            var prevCountry = this.selectedCountryData && this.selectedCountryData.iso2 ? this.selectedCountryData : {};
714            // do this first as it will throw an error and stop if c
714ountryCode is invalid
715            this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {};
716            // update the defaultCountry - we only need the iso2 from now on, so just store that
717            if (this.selectedCountryData.iso2) {
718                this.defaultCountry = this.selectedCountryData.iso2;
719            }
720            this.selectedFlagInner.attr("class", "iti-flag " + countryCode);
721            // update the selected country's title attribute
722            var title = countryCode ? this.selectedCountryData.name + ": +" + this.selectedCountryData.dialCode : "Unknown";
723            this.selectedFlagInner.parent().attr("title", title);
724            if (this.options.separateDialCode) {
725                var dialCode = this.selectedCountryData.dialCode ? "+" + this.selectedCountryData.dialCode : "", parent = this.telInput.parent();
726                if (prevCountry.dialCode) {
727                    parent.removeClass("iti-sdc-" + (prevCountry.dialCode.length + 1));
728                }
729                if (dialCode) {
730                    parent.addClass("iti-sdc-" + dialCode.length);
731                }
732                this.selectedDialCode.text(dialCode);
733            }
734            // and the input's placeholder
735            this._updatePlaceholder();
736            // update the active list item
737            this.countryListItems.removeClass("active");
738            if (countryCode) {
739                this.countryListItems.find(".iti-flag." + countryCode).first().closest(".country").addClass("active");
740            }
741            // on change flag, trigger a custom event
742            if (!isInit && prevCountry.iso2 !== countryCode) {
743                this.telInput.trigger("countrychange", this.selectedCountryData);
744            }
745        },
746        // update the input placeholder to an example number from the currently selected country
747        _updatePlaceholder: function() {
748            if (window.intlTelInputUtils && !this.hadInitialPlaceholder && this.options.autoPlaceholder && this.selectedCountryData) {
749                var numberType = intlTelInputUtils.numberType[this.options.numberType], placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, this.options.nationalMode, numberType) : "";
750                placeholder = this._beforeSetNumber(placeholder);
751                if (typeof this.options.customPlaceholder === "function") {
752                    placeholder = this.options.customPlaceholder(placeholder, this.selectedCountryData);
753                }
754                this.telInput.attr("placeholder", placeholder);
755            }
756        },
757        // called when the user selects a list item from the dropdown
758        _selectListItem: function(listItem) {
759            // update selected flag and active list item
760            this._setFlag(listItem.attr("data-country-code"));
761            this._closeDropdown();
762            this._updateDialCode(listItem.attr("data-dial-code"), true);
763            // focus the input
764            this.telInput.focus();
765            // fix 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
766            if (this.isGoodBrowser) {
767                var len = this.telInput.val().length;
768                this.telInput[0].setSelectionRange(len, len);
769            }
770        },
771        // close the dropdown and unbind any listeners
772        _closeDropdown: function() {
773            this.countryList.addClass("hide");
774            // update the arrow
775            this.selectedFlagInner.children(".iti-arrow").removeClass("up");
776            // unbind key events
777            $(document).off(this.ns);
778            // unbind click-off-to-close
779            $("html").off(this.ns);
780            // unbind hover and click listeners
781            this.countryList.off(this.ns);
782            // remove menu from container
783            if (this.options.dropdownContainer) {
784                if (!this.isMobile) {
785                    $(window).off("scroll" + this.ns);
786                }
787                this.dropdown.detach();
788            }
789        },
790        // check if an element is visible within it's container, else scroll until it is
791        _scrollTo: function(element, middle) {
792            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;
793            if (elementTop < containerTop) {
794                // scroll up
795                if (middle) {
796                    newScrollTop -= middleOffset;
797                }
798                container.scrollTop(newScrollTop);
799            } else if (elementBottom > containerBottom) {
800                // scroll down
801                if (middle) {
802                    newScrollTop += middleOffset;
803                }
804                var heightDifference = containerHeight - elementHeight;
805                container.scrollTop(newScrollTop - heightDifference);
806            }
807        },
808        // replace any existing dial code with the new one
809        // Note: called from _selectListItem and setCountry
810        _updateDialCode: function(newDialCode, hasSelectedListItem) {
811            var inputVal = this.telInput.val(), newNumber;
812            // save having to pass this every time
813            newDialCode = "+" + newDialCode;
814            if (inputVal.charAt(0) == "+") {
815                // there's a plus so we're dealing with a replacement (doesn't matter if nationalMode or not)
816                var prevDialCode = this._getDialCode(inputVal);
817                if (prevDialCode) {
818                    // current number contains a valid dial code, so replace it
819                    newNumber = inputVal.replace(prevDialCode, newDialCode);
820                } else {
821                    // current number contains an invalid dial code, so ditch it
822                    // (no way to determine where the invalid dial code ends and the rest of the number begins)
823                    newNumber = newDialCode;
824                }
825            } else if (this.options.nationalMode || this.options.separateDialCode) {
826                // don't do anything
827                return;
828            } else {
829                // nationalMode is disabled
830                if (inputVal) {
831                    // there is an existing value with no dial code: prefix the new dial code
832                    newNumber = newDialCode + inputVal;
833                } else if (hasSelectedListItem || !this.options.autoHideDialCode) {
834                    // no existing value and either they've just selected a list item, or autoHideDialCode is disabled: insert new dial code
835                    newNumber = newDialCode;
836                } else {
837                    return;
838                }
839            }
840            this.telInput.val(newNumber);
841        },
842        // try and extract a valid international dial code from a full telephone number
843        // Note: returns the raw string inc plus character and any whitespace/dots etc
844        _getDialCode: function(number) {
845            var dialCode = "";
846            // only interested in international numbers (starting with a plus)
847            if (number.charAt(0) == "+") {
848                var numericChars = "";
849                // iterate over chars
850                for (var i = 0; i < number.length; i++) {
851                    var c = number.charAt(i);
852                    // if char is number
853                    if ($.isNumeric(c)) {
854                        numericChars += c;
855                        // if current numericChars make a valid dial code
856                        if (this.countryCodes[numericChars]) {
857                            // store the actual raw string (useful for matching later)
858                            dialCode = number.substr(0, i + 1);
859                        }
860                        // longest dial code is 4 chars
861                        if (numericChars.length == 4) {
862                            break;
863                        }
864                    }
865                }
866            }
867            return dialCode;
868        },
869        // get the input val, adding the dial code if separateDialCode is enabled
870        _getFullNumber: function() {
871            var prefix = this.options.separateDialCode ? "+" + this.selectedCountryData.dialCode : "";
872            return prefix + this.telInput.val();
873        },
874        // remove the dial code if separateDialCode is enabled
875        _beforeSetNumber: function(number) {
876            if (this.options.separateDialCode) {
877                var dialCode = this._getDialCode(number);
878                if (dialCode) {
879                    // US dialCode is "+1", which is what we want
880                    // CA dialCode is "+1 123", which is wrong - should be "+1" (as it has multiple area codes)
881                    // AS dialCode is "+1 684", which is what we want
882                    // Solution: if the country has area codes, then revert to just the dial code
883                    if (this.selectedCountryData.areaCodes !== null) {
884                        dialCode = "+" + this.selectedCountryData.dialCode;
885                    }
886                    // 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
887                    // NOTE: don't just trim all non-numerics as may want to preserve an open parenthesis etc
888                    var start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
889                    number = number.substr(start);
890                }
891            }
892            return this._cap(number);
893        },
894        /********************
895   *  PUBLIC METHODS
896   ********************/
897        // this is called when the geoip call returns
898        handleAutoCountry: function() {
899            if (this.options.initialCountry === "auto") {
900                // we must set this even if there is an initial val in the input: in case the initial val is invali
900d and they delete it - they should see their auto country
901                this.defaultCountry = $.fn[pluginName].autoCountry;
902                // if there's no initial value in the input, then update the flag
903                if (!this.telInput.val()) {
904                    this.setCountry(this.defaultCountry);
905                }
906                this.autoCountryDeferred.resolve();
907            }
908        },
909        // remove plugin
910        destroy: function() {
911            if (this.allowDropdown) {
912                // make sure the dropdown is closed (and unbind listeners)
913                this._closeDropdown();
914                // click event to open dropdown
915                this.selectedFlagInner.parent().off(this.ns);
916                // label click hack
917                this.telInput.closest("label").off(this.ns);
918            }
919            // unbind submit event handler on form
920            if (this.options.autoHideDialCode) {
921                var form = this.telInput.prop("form");
922                if (form) {
923                    $(form).off(this.ns);
924                }
925            }
926            // unbind all events: key events, and focus/blur events if autoHideDialCode=true
927            this.telInput.off(this.ns);
928            // remove markup (but leave the original input)
929            var container = this.telInput.parent();
930            container.before(this.telInput).remove();
931        },
932        // get the extension from the current number
933        getExtension: function() {
934            if (window.intlTelInputUtils) {
935                return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2);
936            }
937            return "";
938        },
939        // format the number to the given format
940        getNumber: function(format) {
941            if (window.intlTelInputUtils) {
942                return intlTelInputUtils.formatNumber(this._getFullNumber(), this.selectedCountryData.iso2, format);
943            }
944            return "";
945        },
946        // get the type of the entered number e.g. landline/mobile
947        getNumberType: function() {
948            if (window.intlTelInputUtils) {
949                return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2);
950            }
951            return -99;
952        },
953        // get the country data for the currently selected flag
954        getSelectedCountryData: function() {
955            // if this is undefined, the plugin will return it's instance instead, so in that case an empty object makes more sense
956            return this.selectedCountryData || {};
957        },
958        // get the validation error
959        getValidationError: function() {
960            if (window.intlTelInputUtils) {
961                return intlTelInputUtils.getValidationError(this._getFullNumber(), this.selectedCountryData.iso2);
962            }
963            return -99;
964        },
965        // validate the input val - assumes the global function isValidNumber (from utilsScript)
966        isValidNumber: function() {
967            var val = $.trim(this._getFullNumber()), countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : "";
968            return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null;
969        },
970        // update the selected flag, and update the input val accordingly
971        setCountry: function(countryCode) {
972            countryCode = countryCode.toLowerCase();
973            // check if already selected
974            if (!this.selectedFlagInner.hasClass(countryCode)) {
975                this._setFlag(countryCode);
976                this._updateDialCode(this.selectedCountryData.dialCode, false);
977            }
978        },
979        // set the input value and update the flag
980        // NOTE: format arg is for public method: to allow devs to format how they want
981        setNumber: function(number, format) {
982            // we must update the flag first, which updates this.selectedCountryData, which is used for formatting the number before displaying it
983            this._updateFlagFromNumber(number);
984            this._updateValFromNumber(number, $.isNumeric(format), format);
985        },
986        // this is called when the utils request completes
987        handleUtils: function() {
988            // if the request was successful
989            if (window.intlTelInputUtils) {
990                // if there's an initial value in the input, then format it
991                if (this.telInput.val()) {
992                    this._updateValFromNumber(this.telInput.val(), this.options.formatOnInit);
993                }
994                this._updatePlaceholder();
995            }
996            this.utilsScriptDeferred.resolve();
997        }
998    };
999    // using https://github.com/jquery-boilerplate/jquery-boilerplate/wiki/Extending-jQuery-Boilerplate
1000    // (adapted to allow public functions)
1001    $.fn[pluginName] = function(options) {
1002        var args = arguments;
1003        // Is the first parameter an object (options), or was omitted,
1004        // instantiate a new instance of the plugin.
1005        if (options === undefined || typeof options === "object") {
1006            // collect all of the deferred objects for all instances created with this selector
1007            var deferreds = [];
1008            this.each(function() {
1009                if (!$.data(this, "plugin_" + pluginName)) {
1010                    var instance = new Plugin(this, options);
1011                    var instanceDeferreds = instance._init();
1012                    // we now have 2 deffereds: 1 for auto country, 1 for utils script
1013                    deferreds.push(instanceDeferreds[0]);
1014                    deferreds.push(instanceDeferreds[1]);
1015                    $.data(this, "plugin_" + pluginName, instance);
1016                }
1017            });
1018            // return the promise from the "master" deferred object that tracks all the others
1019            return $.when.apply(null, deferreds);
1020        } else if (typeof options === "string" && options[0] !== "_") {
1021            // If the first parameter is a string and it doesn't start
1022            // with an underscore or "contains" the `init`-function,
1023            // treat this as a call to a public method.
1024            // Cache the method call to make it possible to return a value
1025            var returns;
1026            this.each(function() {
1027                var instance = $.data(this, "plugin_" + pluginName);
1028                // Tests that there's already a plugin-instance
1029                // and checks that the requested public method exists
1030                if (instance instanceof Plugin && typeof instance[options] === "function") {
1031                    // Call the method of our plugin instance,
1032                    // and pass it the supplied arguments.
1033                    returns = instance[options].apply(instance, Array.prototype.slice.call(args, 1));
1034                }
1035                // Allow instances to be destroyed via the 'destroy' method
1036                if (options === "destroy") {
1037                    $.data(this, "plugin_" + pluginName, null);
1038                }
1039            });
1040            // If the earlier cached method gives a value back return the value,
1041            // otherwise return this to preserve chainability.
1042            return returns !== undefined ? returns : this;
1043        }
1044    };
1045    /********************
1046 *  STATIC METHODS
1047 ********************/
1048    // get the country data object
1049    $.fn[pluginName].getCountryData = function() {
1050        return allCountries;
1051    };
1052    // load the utils script
1053    $.fn[pluginName].loadUtils = function(path, utilsScriptDeferred) {
1054        if (!$.fn[pluginName].loadedUtilsScript) {
1055            // 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)
1056            $.fn[pluginName].loadedUtilsScript = true;
1057            // dont use $.getScript as it prevents caching
1058            $.ajax({
1059                url: path,
1060                complete: function() {
1061                    // tell all instances that the utils request is complete
1062                    $(".intl-tel-input input").intlTelInput("handleUtils");
1063                },
1064                dataType: "script",
1065                cache: true
1066            });
1067        } else if (utilsScriptDeferred) {
1068            utilsScriptDeferred.resolve();
1069        }
1070    };
1071    // version
1072    $.fn[pluginName].version = "8.5.2";
1073    // Tell JSHint to ignore this warning: "character may get silently deleted by one or more browsers"
1074    // jshint -W100
1075    // Array of country objects for the flag dropdown.
1076    // Each contains a name, country code (ISO 3166-1 alpha-2) and dial code.
1077    // Originally from https://github.com/mledoze/countries
1078    // then with a couple of manual re-arrangements to be alphabetical
1079    // then changed Kazakhstan from +76 to +7
1080    // and Vatican City from +379 to +39 (see issue 50)
1081    // and Caribean Netherlands from +5997 to +599
1082    // and Curacao from +5999 to +599
1083    // Removed:  Kosovo, Pitcairn Islands, South Georgia
1084    // UPDATE Sept 12th 2015
1085    // List of regions that have iso2 country codes, which I have chosen to omit:
1086    // (based on this information: https://en.wikipedia.org/wiki/List_of_country_calling_codes)
1087    // AQ - Antarctica - all different country codes depending on which "base"
1088    // BV - Bouvet Island - no calling code
1089    // GS - South Georgia and the South Sandwich Islands - "inhospitable collection of islands" - same flag and calling code as Falkland Islands
1090    // HM - Heard Island and McDonald Islands - no calling code
1091    // PN - Pitcairn - tiny population (56), same calling code as New Zealand
1092    // TF - French Southern Territories - no calling code
1093    // UM - United States Minor Outlying Islands - no calling code
1094    // UPDATE the criteria of supported countries or territories (see issue 297)
1095    // Have an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
1096    // Have a country calling code: https://en.wikipedia.org/wiki/List_of_country_calling_codes
1097    // Have a flag
1098    // Must be supported by libphonenumber: https://github.com/googlei18n/libphonenumber
1099    // Update: converted objects to arrays to save bytes!
1100    // Update: added "priority" for countries with the same dialCode as others
1101    // Update: added array of area codes for countries with the same dialCode as others
1102    // So each country array has the following information:
1103    // [
1104    //    Country name,
1105    //    iso2 code,
1106    //    International dial code,
1107    //    Order (if >1 country with same dial code),
1108    //    Area codes (if >1 country with same dial code)
1109    // ]
1110    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
1110aat)", "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" ], [ "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 ] ];
1111    // loop over all of the countries above
1112    for (var i = 0; i < allCountries.length; i++) {
1113        var c = allCountries[i];
1114        allCountries[i] = {
1115            name: c[0],
1116            iso2: c[1],
1117            dialCode: c[2],
1118            priority: c[3] || 0,
1119            areaCodes: c[4] || null
1120        };
1121    }
1122});

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.