PageSourceSearch

https://www.rra.gov.rw/typo3conf/ext/rra_ui/Resources/Public/chatwidget/tel/intlTelInput.js?1529247052

js rra.gov.rw collected 2026-09-27 20:57:09 UTC 68,678 bytes, 1,113 lines download raw bytes

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

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.