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