1/* 2 * International Telephone Input v8.4.7 3 * https://github.com/jackocnr/intl-tel-input.git 4 * Licensed under the MIT license 5 */ 6// wrap in UMD - see https://github.com/umdjs/umd/blob/master/jqueryPluginCommonjs.js 7(function(factory) { 8 if (typeof define === "function" && define.amd) { 9 define([ "jquery" ], function($) { 10 factory($, window, document); 11 }); 12 } else if (typeof module === "object" && module.exports) { 13 module.exports = factory(require("jquery"), window, document); 14 } else { 15 factory(jQuery, window, document); 16 } 17})(function($, window, document, undefined) { 18 "use strict"; 19 // these vars persist through all instances of the plugin 20 var pluginName = "intlTelInput", id = 1, // give each instance it's own id for namespaced event handling 21 defaults = { 22 // whether or not to allow the dropdown 23 allowDropdown: true, 24 // if there is just a dial code in the input: remove it on blur, and re-add it on focus 25 autoHideDialCode: true, 26 // add or remove input placeholder with an example number for the selected country 27 autoPlaceholder: true, 28 // modify the auto placeholder 29 customPlaceholder: null, 30 // append menu to a specific element 31 dropdownContainer: "", 32 // don't display these countries 33 excludeCountries: [], 34 // format the input value during initialisation 35 formatOnInit: true, 36 // geoIp lookup function 37 geoIpLookup: null, 38 // initial country 39 initialCountry: "", 40 // don't insert international dial codes 41 nationalMode: true, 42 // number type to use for placeholders 43 numberType: "MOBILE", 44 // display only these countries 45 onlyCountries: [], 46 // the countries at the top of the list. defaults to united states and united kingdom 47 preferredCountries: [ "us", "gb" ], 48 // display the country dial code next to the selected flag so it's not part of the typed number 49 separateDialCode: false, 50 // specify the path to the libphonenumber script to enable validation/formatting 51 utilsScript: "" 52 }, keys = { 53 UP: 38, 54 DOWN: 40, 55 ENTER: 13, 56 ESC: 27, 57 PLUS: 43, 58 A: 65, 59 Z: 90, 60 SPACE: 32, 61 TAB: 9 62 }; 63 // keep track of if the window.load event has fired as impossible to check after the fact 64 $(window).load(function() { 65 // UPDATE: use a public static field so we can fudge it in the tests 66 $.fn[pluginName].windowLoaded = true; 67 }); 68 function Plugin(element, options) { 69 this.telInput = $(element); 70 this.options = $.extend({}, defaults, options); 71 // event namespace 72 this.ns = "." + pluginName + id++; 73 // Chrome, FF, Safari, IE9+ 74 this.isGoodBrowser = Boolean(element.setSelectionRange); 75 this.hadInitialPlaceholder = Boolean($(element).attr("placeholder")); 76 } 77 Plugin.prototype = { 78 _init: function() { 79 // if in nationalMode, disable options relating to dial codes 80 if (this.options.nationalMode) { 81 this.options.autoHideDialCode = false; 82 } 83 // if separateDialCode then doesn't make sense to A) insert dial code into input (autoHideDialCode), and B) display national numbers (because we're displaying the country dial code next to them) 84 if (this.options.separateDialCode) { 85 this.options.autoHideDialCode = this.options.nationalMode = false; 86 // let's force this for now for simplicity - we can support this later if need be 87 this.options.allowDropdown = true; 88 } 89 // we cannot just test screen size as some smartphones/website meta tags will report desktop resolutions 90 // Note: for some reason jasmine breaks if you put this in the main Plugin function with the rest of these declarations 91 // Note: to target Android Mobiles (and not Tablets), we must find "Android" and "Mobile" 92 this.isMobile = /Android.+Mobile|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); 93 if (this.isMobile) { 94 // trigger the mobile dropdown css 95 $("body").addClass("iti-mobile"); 96 // on mobile, we want a full screen dropdown, so we must append it to the body 97 if (!this.options.dropdownContainer) { 98 this.options.dropdownContainer = "body"; 99 } 100 } 101 // we return these deferred objects from the _init() call so they can be watched, and then we resolve them when each specific request returns 102 // Note: again, jasmine breaks when I put these in the Plugin function 103 this.autoCountryDeferred = new $.Deferred(); 104 this.utilsScriptDeferred = new $.Deferred(); 105 // process all the data: onlyCountries, excludeCountries, preferredCountries etc 106 this._processCountryData(); 107 // generate the markup 108 this._generateMarkup(); 109 // set the initial state of the input value and the selected flag 110 this._setInitialState(); 111 // start all of the event listeners: autoHideDialCode, input keydown, selectedFlag click 112 this._initListeners(); 113 // utils script, and auto country 114 this._initRequests(); 115 // return the deferreds 116 return [ this.autoCountryDeferred, this.utilsScriptDeferred ]; 117 }, 118 /******************** 119 * PRIVATE METHODS 120 ********************/ 121 // prepare all of the country data, including onlyCountries, excludeCountries and preferredCountries options 122 _processCountryData: function() { 123 // process onlyCountries or excludeCountries array if present 124 this._processAllCountries(); 125 // process the countryCodes map 126 this._processCountryCodes(); 127 // process the preferredCountries 128 this._processPreferredCountries(); 129 }, 130 // add a country code to this.countryCodes 131 _addCountryCode: function(iso2, dialCode, priority) { 132 if (!(dialCode in this.countryCodes)) { 133 this.countryCodes[dialCode] = []; 134 } 135 var index = priority || 0; 136 this.countryCodes[dialCode][index] = iso2; 137 }, 138 // filter the given countries using the process function 139 _filterCountries: function(countryArray, processFunc) { 140 var i; 141 // standardise case 142 for (i = 0; i < countryArray.length; i++) { 143 countryArray[i] = countryArray[i].toLowerCase(); 144 } 145 // build instance country array 146 this.countries = []; 147 for (i = 0; i < allCountries.length; i++) { 148 if (processFunc($.inArray(allCountries[i].iso2, countryArray))) { 149 this.countries.push(allCountries[i]); 150 } 151 } 152 }, 153 // process onlyCountries or excludeCountries array if present 154 _processAllCountries: function() { 155 if (this.options.onlyCountries.length) { 156 // process onlyCountries option 157 this._filterCountries(this.options.onlyCountries, function(inArray) { 158 // if country is in array 159 return inArray != -1; 160 }); 161 } else if (this.options.excludeCountries.length) { 162 // process excludeCountries option 163 this._filterCountries(this.options.excludeCountries, function(inArray) { 164 // if country is not in array 165 return inArray == -1; 166 }); 167 } else { 168 this.countries = allCountries; 169 } 170 }, 171 // process the countryCodes map 172 _processCountryCodes: function() { 173 this.countryCodes = {}; 174 for (var i = 0; i < this.countries.length; i++) { 175 var c = this.countries[i]; 176 this._addCountryCode(c.iso2, c.dialCode, c.priority); 177 // area codes 178 if (c.areaCodes) { 179 for (var j = 0; j < c.areaCodes.length; j++) { 180 // full dial code is country code + dial code 181 this._addCountryCode(c.iso2, c.dialCode + c.areaCodes[j]); 182 } 183 } 184 } 185 }, 186 // process preferred countries - iterate through the preferences, fetching the country data for each one 187 _processPreferredCountries: function() { 188 this.preferredCountries = []; 189 for (var i = 0; i < this.options.preferredCountries.length; i++) { 190 var countryCode = this.options.preferredCountries[i].toLowerCase(), countryData = this._getCountryData(countryCode, false, true); 191 if (countryData) { 192 this.preferredCountries.push(countryData); 193 } 194 } 195 }, 196 // generate all of the markup for the plugin: the selected flag overlay, and the dropdown 197 _generateMarkup: function() { 198 // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can easily put the plugin in an inconsistent state e.g. the wrong flag selected for the autocompleted number, which on submit c
198ould mean the wrong number is saved (esp in nationalMode) 199 this.telInput.attr("autocomplete", "off"); 200 // containers (mostly for positioning) 201 var parentClass = "intl-tel-input"; 202 if (this.options.allowDropdown) { 203 parentClass += " allow-dropdown"; 204 } 205 if (this.options.separateDialCode) { 206 parentClass += " separate-dial-code"; 207 } 208 this.telInput.wrap($("<div>", { 209 "class": parentClass 210 })); 211 this.flagsContainer = $("<div>", { 212 "class": "flag-container" 213 }).insertBefore(this.telInput); 214 // currently selected flag (displayed to left of input) 215 var selectedFlag = $("<div>", { 216 "class": "selected-flag" 217 }); 218 selectedFlag.appendTo(this.flagsContainer); 219 this.selectedFlagInner = $("<div>", { 220 "class": "iti-flag" 221 }).appendTo(selectedFlag); 222 if (this.options.separateDialCode) { 223 this.selectedDialCode = $("<div>", { 224 "class": "selected-dial-code" 225 }).appendTo(selectedFlag); 226 } 227 if (this.options.allowDropdown) { 228 // make element focusable and tab naviagable 229 selectedFlag.attr("tabindex", "0"); 230 // CSS triangle 231 $("<div>", { 232 "class": "iti-arrow" 233 }).appendTo(selectedFlag); 234 // country dropdown: preferred countries, then divider, then all countries 235 this.countryList = $("<ul>", { 236 "class": "country-list hide" 237 }); 238 if (this.preferredCountries.length) { 239 this._appendListItems(this.preferredCountries, "preferred"); 240 $("<li>", { 241 "class": "divider" 242 }).appendTo(this.countryList); 243 } 244 this._appendListItems(this.countries, ""); 245 // this is useful in lots of places 246 this.countryListItems = this.countryList.children(".country"); 247 // create dropdownContainer markup 248 if (this.options.dropdownContainer) { 249 this.dropdown = $("<div>", { 250 "class": "intl-tel-input iti-container" 251 }).append(this.countryList); 252 } else { 253 this.countryList.appendTo(this.flagsContainer); 254 } 255 } else { 256 // a little hack so we don't break anything 257 this.countryListItems = $(); 258 } 259 }, 260 // add a country <li> to the countryList <ul> container 261 _appendListItems: function(countries, className) { 262 // we create so many DOM elements, it is faster to build a temp string 263 // and then add everything to the DOM in one go at the end 264 var tmp = ""; 265 // for each country 266 for (var i = 0; i < countries.length; i++) { 267 var c = countries[i]; 268 // open the list item 269 tmp += "<li class='country " + className + "' data-dial-code='" + c.dialCode + "' data-country-code='" + c.iso2 + "'>"; 270 // add the flag 271 tmp += "<div class='flag-box'><div class='iti-flag " + c.iso2 + "'></div></div>"; 272 // and the country name and dial code 273 tmp += "<span class='country-name'>" + c.name + "</span>"; 274 tmp += "<span class='dial-code'>+" + c.dialCode + "</span>"; 275 // close the list item 276 tmp += "</li>"; 277 } 278 this.countryList.append(tmp); 279 }, 280 // set the initial state of the input value and the selected flag by: 281 // 1. extracting a dial code from the given number 282 // 2. using explicit initialCountry 283 // 3. picking the first preferred country 284 // 4. picking the first country 285 _setInitialState: function() { 286 var val = this.telInput.val(); 287 // if we already have a dial code we can go ahead and set the flag, else fall back to default 288 if (this._getDialCode(val)) { 289 this._updateFlagFromNumber(val, true); 290 } else if (this.options.initialCountry !== "auto") { 291 // see if we should select a flag 292 if (this.options.initialCountry) { 293 this._setFlag(this.options.initialCountry, true); 294 } else {
295 // no dial code and no initialCountry, so default to first in list 296 this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2; 297 if (!val) { 298 this._setFlag(this.defaultCountry, true); 299 } 300 } 301 // if empty and no nationalMode and no autoHideDialCode then insert the default dial code 302 if (!val && !this.options.nationalMode && !this.options.autoHideDialCode && !this.options.separateDialCode) { 303 this.telInput.val("+" + this.selectedCountryData.dialCode); 304 } 305 } 306 // NOTE: if initialCountry is set to auto, that will be handled separately 307 // format 308 if (val) { 309 // this wont be run after _updateDialCode as that's only called if no val 310 this._updateValFromNumber(val, this.options.formatOnInit); 311 } 312 }, 313 // initialise the main event listeners: input keyup, and click selected flag 314 _initListeners: function() { 315 this._initKeyListeners(); 316 if (this.options.autoHideDialCode) { 317 this._initFocusListeners(); 318 } 319 if (this.options.allowDropdown) { 320 this._initDropdownListeners(); 321 } 322 }, 323 // initialise the dropdown listeners 324 _initDropdownListeners: function() { 325 var that = this; 326 // hack for input nested inside label: clicking the selected-flag to open the dropdown would then automatically trigger a 2nd click on the input which would close it again 327 var label = this.telInput.closest("label"); 328 if (label.length) { 329 label.on("click" + this.ns, function(e) { 330 // if the dropdown is closed, then focus the input, else ignore the click 331 if (that.countryList.hasClass("hide")) { 332 that.telInput.focus(); 333 } else { 334 e.preventDefault(); 335 } 336 }); 337 } 338 // toggle country dropdown on click 339 var selectedFlag = this.selectedFlagInner.parent(); 340 selectedFlag.on("click" + this.ns, function(e) { 341 // only intercept this event if we're opening the dropdown 342 // else let it bubble up to the top ("click-off-to-close" listener) 343 // we cannot just stopPropagation as it may be needed to close another instance 344 if (that.countryList.hasClass("hide") && !that.telInput.prop("disabled") && !that.telInput.prop("readonly")) { 345 that._showDropdown(); 346 } 347 }); 348 // open dropdown list if currently focused 349 this.flagsContainer.on("keydown" + that.ns, function(e) { 350 var isDropdownHidden = that.countryList.hasClass("hide"); 351 if (isDropdownHidden && (e.which == keys.UP || e.which == keys.DOWN || e.which == keys.SPACE || e.which == keys.ENTER)) { 352 // prevent form from being submitted if "ENTER" was pressed 353 e.preventDefault(); 354 // prevent event from being handled again by document 355 e.stopPropagation(); 356 that._showDropdown(); 357 } 358 // allow navigation from dropdown to input on TAB 359 if (e.which == keys.TAB) { 360 that._closeDropdown(); 361 } 362 }); 363 }, 364 // init many requests: utils script / geo ip lookup 365 _initRequests: function() { 366 var that = this; 367 // if the user has specified the path to the utils script, fetch it on window.load, else resolve 368 if (this.options.utilsScript) { 369 // if the plugin is being initialised after the window.load event has already been fired 370 if ($.fn[pluginName].windowLoaded) { 371 $.fn[pluginName].loadUtils(this.options.utilsScript, this.utilsScriptDeferred); 372 } else { 373 // wait until the load event so we don't block any other requests e.g. the flags image 374 $(window).load(function() { 375 $.fn[pluginName].loadUtils(that.options.utilsScript, that.utilsScriptDeferred); 376 }); 377 } 378 } else { 379 this.utilsScriptDeferred.resolve(); 380 } 381 if (this.options.initialCountry === "auto") { 382 this._loadAutoCountry(); 383 } else { 384 this.autoCountryDeferred.resolve(); 385 } 386 }, 387 // perform the geo ip lookup 388 _loadAutoCountry: function() { 389 var that = this;
390 // check for cookie 391 var cookieAutoCountry = window.Cookies ? Cookies.get("itiAutoCountry") : ""; 392 if (cookieAutoCountry) { 393 $.fn[pluginName].autoCountry = cookieAutoCountry; 394 } 395 // 3 options: 396 // 1) already loaded (we're done) 397 // 2) not already started loading (start) 398 // 3) already started loading (do nothing - just wait for loading callback to fire) 399 if ($.fn[pluginName].autoCountry) { 400 this.handleAutoCountry(); 401 } else if (!$.fn[pluginName].startedLoadingAutoCountry) { 402 // don't do this twice! 403 $.fn[pluginName].startedLoadingAutoCountry = true; 404 if (typeof this.options.geoIpLookup === "function") { 405 this.options.geoIpLookup(function(countryCode) { 406 $.fn[pluginName].autoCountry = countryCode.toLowerCase(); 407 if (window.Cookies) { 408 Cookies.set("itiAutoCountry", $.fn[pluginName].autoCountry, { 409 path: "/" 410 }); 411 } 412 // tell all instances the auto country is ready 413 // TODO: this should just be the current instances 414 // UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight away (e.g. if they have already done the geo ip lookup somewhere else). Using setTimeout means that the current thread of execution will finish before executing this, which allows the plugin to finish initialising. 415 setTimeout(function() { 416 $(".intl-tel-input input").intlTelInput("handleAutoCountry"); 417 }); 418 }); 419 } 420 } 421 }, 422 // initialize any key listeners 423 _initKeyListeners: function() { 424 var that = this; 425 // update flag on keyup 426 // (keep this listener separate otherwise the setTimeout breaks all the tests) 427 this.telInput.on("keyup" + this.ns, function() { 428 that._updateFlagFromNumber(that.telInput.val()); 429 }); 430 // update flag on cut/paste events (now supported in all major browsers) 431 this.telInput.on("cut" + this.ns + " paste" + this.ns + " keyup" + this.ns, function() { 432 // hack because "paste" event is fired before input is updated 433 setTimeout(function() { 434 that._updateFlagFromNumber(that.telInput.val()); 435 }); 436 }); 437 }, 438 // adhere to the input's maxlength attr 439 _cap: function(number) { 440 var max = this.telInput.attr("maxlength"); 441 return max && number.length > max ? number.substr(0, max) : number; 442 }, 443 // listen for mousedown, focus and blur 444 _initFocusListeners: function() { 445 var that = this; 446 // mousedown decides where the cursor goes, so if we're focusing we must preventDefault as we'll be inserting the dial code, and we want the cursor to be at the end no matter where they click 447 this.telInput.on("mousedown" + this.ns, function(e) { 448 if (!that.telInput.is(":focus") && !that.telInput.val()) { 449 e.preventDefault(); 450 // but this also cancels the focus, so we must trigger that manually 451 that.telInput.focus(); 452 } 453 }); 454 // on focus: if empty, insert the dial code for the currently selected flag 455 this.telInput.on("focus" + this.ns, function(e) { 456 if (!that.telInput.val() && !that.telInput.prop("readonly") && that.selectedCountryData.dialCode) { 457 // insert the dial code 458 that.telInput.val("+" + that.selectedCountryData.dialCode); 459 // after auto-inserting a dial code, if the first key they hit is '+' then assume they are entering a new number, so remove the dial code. use keypress instead of keydown because keydown gets triggered for the shift key (required to hit the + key), and instead of keyup because that shows the new '+' before removing the old one 460 that.telInput.one("keypress.plus" + that.ns, function(e) { 461 if (e.which == keys.PLUS) { 462 that.telInput.val(""); 463 } 464 }); 465 // after tabbing in, make sure the cursor is at the end we must use setTimeout to get outside of the focus handler as it seems the selection happens after that 466 setTimeout(function() { 467 var input = that.telInput[0]; 468 if (that.isGoodBrowser) { 469 var len = that.telInput.val().length; 470 input.setSelectionRange(len, len); 471 } 472 }); 473 } 474 }); 475 // on blur: if just a dial code then remove it 476 this.telInput.on("blur" + this.ns, function() { 477 var value = that.telInput.val(), startsPlus = value.charAt(0) == "+"; 478 if (startsPlus) { 479 var numeric = that._getNumeric(value); 480 // if just a plus, or if just a dial code 481 if (!numeric || that.selectedCountryData.dialCode == numeric) { 482 that.telInput.val(""); 483 } 484 } 485 // remove the keypress listener we added on focus 486 that.telInput.off("keypress.plus" + that.ns); 487 }); 488 }, 489 // extract the numeric digits from the given string 490 _getNumeric: function(s) { 491 return s.replace(/\D/g, ""); 492 }, 493 // show the dropdown 494 _showDropdown: function() { 495 this._setDropdownPosition(); 496 // update highlighting and scroll to active list item 497 var activeListItem = this.countryList.children(".active"); 498 if (activeListItem.length) {
499 this._highlightListItem(activeListItem); 500 this._scrollTo(activeListItem); 501 } 502 // bind all the dropdown-related listeners: mouseover, click, click-off, keydown 503 this._bindDropdownListeners(); 504 // update the arrow 505 this.selectedFlagInner.children(".iti-arrow").addClass("up"); 506 }, 507 // decide where to position dropdown (depends on position within viewport, and scroll) 508 _setDropdownPosition: function() { 509 var that = this; 510 if (this.options.dropdownContainer) { 511 this.dropdown.appendTo(this.options.dropdownContainer); 512 } 513 // show the menu and grab the dropdown height 514 this.dropdownHeight = this.countryList.removeClass("hide").outerHeight(); 515 if (!this.isMobile) { 516 var pos = this.telInput.offset(), inputTop = pos.top, windowTop = $(window).scrollTop(), // dropdownFitsBelow = (dropdownBottom < windowBottom) 517 dropdownFitsBelow = inputTop + this.telInput.outerHeight() + this.dropdownHeight < windowTop + $(window).height(), dropdownFitsAbove = inputTop - this.dropdownHeight > windowTop; 518 // by default, the dropdown will be below the input. If we want to position it above the input, we add the dropup class. 519 this.countryList.toggleClass("dropup", !dropdownFitsBelow && dropdownFitsAbove); 520 // if dropdownContainer is enabled, calculate postion 521 if (this.options.dropdownContainer) { 522 // 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. 523 var extraTop = !dropdownFitsBelow && dropdownFitsAbove ? 0 : this.telInput.innerHeight(); 524 // calculate placement 525 this.dropdown.css({ 526 top: inputTop + extraTop, 527 left: pos.left 528 }); 529 // close menu on window scroll 530 $(window).on("scroll" + this.ns, function() { 531 that._closeDropdown(); 532 }); 533 } 534 } 535 }, 536 // we only bind dropdown listeners when the dropdown is open 537 _bindDropdownListeners: function() { 538 var that = this; 539 // when mouse over a list item, just highlight that one 540 // we add the class "highlight", so if they hit "enter" we know which one to select 541 this.countryList.on("mouseover" + this.ns, ".country", function(e) { 542 that._highlightListItem($(this)); 543 }); 544 // listen for country selection 545 this.countryList.on("click" + this.ns, ".country", function(e) { 546 that._selectListItem($(this)); 547 }); 548 // click off to close 549 // (except when this initial opening click is bubbling up) 550 // we cannot just stopPropagation as it may be needed to close another instance 551 var isOpening = true; 552 $("html").on("click" + this.ns, function(e) { 553 if (!isOpening) { 554 that._closeDropdown(); 555 } 556 isOpening = false; 557 }); 558 // listen for up/down scrolling, enter to select, or letters to jump to country name. 559 // use keydown as keypress doesn't fire for non-char keys and we want to catch if they 560 // just hit down and hold it to scroll down (no keyup event). 561 // listen on the document because that's where key events are triggered if no input has focus 562 var query = "", queryTimer = null; 563 $(document).on("keydown" + this.ns, function(e) { 564 // prevent down key from scrolling the whole page, 565 // and enter key from submitting a form etc 566 e.preventDefault(); 567 if (e.which == keys.UP || e.which == keys.DOWN) { 568 // up and down to navigate 569 that._handleUpDownKey(e.which); 570 } else if (e.which == keys.ENTER) { 571 // enter to select 572 that._handleEnterKey(); 573 } else if (e.which == keys.ESC) { 574 // esc to close 575 that._closeDropdown(); 576 } else if (e.which >
576= keys.A && e.which <= keys.Z || e.which == keys.SPACE) { 577 // upper case letters (note: keyup/keydown only return upper case letters) 578 // jump to countries that start with the query string 579 if (queryTimer) { 580 clearTimeout(queryTimer); 581 } 582 query += String.fromCharCode(e.which); 583 that._searchForCountry(query); 584 // if the timer hits 1 second, reset the query 585 queryTimer = setTimeout(function() { 586 query = ""; 587 }, 1e3); 588 } 589 }); 590 }, 591 // highlight the next/prev item in the list (and ensure it is visible) 592 _handleUpDownKey: function(key) { 593 var current = this.countryList.children(".highlight").first(); 594 var next = key == keys.UP ? current.prev() : current.next(); 595 if (next.length) { 596 // skip the divider 597 if (next.hasClass("divider")) { 598 next = key == keys.UP ? next.prev() : next.next(); 599 } 600 this._highlightListItem(next); 601 this._scrollTo(next); 602 } 603 }, 604 // select the currently highlighted item 605 _handleEnterKey: function() { 606 var currentCountry = this.countryList.children(".highlight").first(); 607 if (currentCountry.length) { 608 this._selectListItem(currentCountry); 609 } 610 }, 611 // find the first list item whose name starts with the query string 612 _searchForCountry: function(query) { 613 for (var i = 0; i < this.countries.length; i++) { 614 if (this._startsWith(this.countries[i].name, query)) { 615 var listItem = this.countryList.children("[data-country-code=" + this.countries[i].iso2 + "]").not(".preferred"); 616 // update highlighting and scroll 617 this._highlightListItem(listItem); 618 this._scrollTo(listItem, true); 619 break; 620 } 621 } 622 }, 623 // check if (uppercase) string a starts with string b 624 _startsWith: function(a, b) { 625 return a.substr(0, b.length).toUpperCase() == b; 626 }, 627 // update the input's value to the given val (format first if possible) 628 // NOTE: this is called from _setInitialState, handleUtils and setNumber
629 _updateValFromNumber: function(number, doFormat, format) { 630 if (doFormat && window.intlTelInputUtils && this.selectedCountryData) { 631 if (!$.isNumeric(format)) { 632 format = this.options.nationalMode || number.charAt(0) != "+" ? intlTelInputUtils.numberFormat.NATIONAL : intlTelInputUtils.numberFormat.INTERNATIONAL; 633 } 634 number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format); 635 } 636 number = this._beforeSetNumber(number); 637 this.telInput.val(number); 638 }, 639 // check if need to select a new flag based on the given number 640 // Note: called from _setInitialState, keyup handler, setNumber 641 _updateFlagFromNumber: function(number, isInit) { 642 // 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 643 // 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 644 if (number && this.options.nationalMode && this.selectedCountryData && this.selectedCountryData.dialCode == "1" && number.charAt(0) != "+") { 645 if (number.charAt(0) != "1") { 646 number = "1" + number; 647 } 648 number = "+" + number; 649 } 650 // try and extract valid dial code from input 651 var dialCode = this._getDialCode(number), countryCode = null; 652 if (dialCode) { 653 // check if one of the matching countries is already selected 654 var countryCodes = this.countryCodes[this._getNumeric(dialCode)], alreadySelected = this.selectedCountryData && $.inArray(this.selectedCountryData.iso2, countryCodes) != -1; 655 // if a matching country is not already selected (or this is an unknown NANP area code): choose the first in the list 656 if (!alreadySelected || this._isUnknownNanp(number, dialCode)) { 657 // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first non-empty index 658 for (var j = 0; j < countryCodes.length; j++) { 659 if (countryCodes[j]) { 660 countryCode = countryCodes[j]; 661 break; 662 } 663 } 664 } 665 } else if (number.charAt(0) == "+" && this._getNumeric(number).length) { 666 // invalid dial code, so empty 667 // Note: use getNumeric here because the number has not been formatted yet, so could contain bad chars 668 countryCode = ""; 669 } else if (!number || number == "+") { 670 // empty, or just a plus, so default 671 countryCode = this.defaultCountry; 672 } 673 if (countryCode !== null) { 674 this._setFlag(countryCode, isInit); 675 } 676 }, 677 // check if the given number contains an unknown area code from the North American Numbering Plan i.e. the only dialCode that could be extracted was +1 (instead of say +1 702) and the actual number's length is >=4 678 _isUnknownNanp: function(number, dialCode) { 679 return dialCode == "+1" && this._getNumeric(number).length >= 4; 680 }, 681 // remove highlighting from other list items and highlight the given item 682 _highlightListItem: function(listItem) { 683 this.countryListItems.removeClass("highlight"); 684 listItem.addClass("highlight"); 685 }, 686 // find the country data for the given country code 687 // the ignoreOnlyCountriesOption is only used during init() while parsing the onlyCountries array 688 _getCountryData: function(countryCode, ignoreOnlyCountriesOption, allowFail) { 689 var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries; 690 for (var i = 0; i < countryList.length; i++) { 691 if (countryList[i].iso2 == countryCode) { 692 return countryList[i]; 693 } 694 } 695 if (allowFail) { 696 return null; 697 } else { 698 throw new Error("No country data for '" + countryCode + "'"); 699 } 700 }, 701 // select the given flag, update the placeholder and the active list item 702 // Note: called from _setInitialState, _updateFlagFromNumber, _selectListItem, setCountry 703 _setFlag: function(countryCode, isInit) { 704 var prevCountry = this.selectedCountryData && this.selectedCountryData.iso2 ? this.selectedCountryData : {}; 705 // do this first as it will throw an error and stop if c
705ountryCode is invalid 706 this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {}; 707 // update the defaultCountry - we only need the iso2 from now on, so just store that 708 if (this.selectedCountryData.iso2) { 709 this.defaultCountry = this.selectedCountryData.iso2; 710 } 711 this.selectedFlagInner.attr("class", "iti-flag " + countryCode); 712 // update the selected country's title attribute 713 var title = countryCode ? this.selectedCountryData.name + ": +" + this.selectedCountryData.dialCode : "Unknown"; 714 this.selectedFlagInner.parent().attr("title", title); 715 if (this.options.separateDialCode) { 716 var dialCode = this.selectedCountryData.dialCode ? "+" + this.selectedCountryData.dialCode : "", parent = this.telInput.parent(); 717 if (prevCountry.dialCode) { 718 parent.removeClass("iti-sdc-" + (prevCountry.dialCode.length + 1)); 719 } 720 if (dialCode) { 721 parent.addClass("iti-sdc-" + dialCode.length); 722 } 723 this.selectedDialCode.text(dialCode); 724 } 725 // and the input's placeholder 726 this._updatePlaceholder(); 727 // update the active list item 728 this.countryListItems.removeClass("active"); 729 if (countryCode) { 730 this.countryListItems.find(".iti-flag." + countryCode).first().closest(".country").addClass("active"); 731 } 732 // on change flag, trigger a custom event 733 if (!isInit && prevCountry.iso2 !== countryCode) { 734 this.telInput.trigger("countrychange", this.selectedCountryData); 735 } 736 }, 737 // update the input placeholder to an example number from the currently selected country 738 _updatePlaceholder: function() { 739 if (window.intlTelInputUtils && !this.hadInitialPlaceholder && this.options.autoPlaceholder && this.selectedCountryData) { 740 var numberType = intlTelInputUtils.numberType[this.options.numberType], placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, this.options.nationalMode, numberType) : ""; 741 placeholder = this._beforeSetNumber(placeholder); 742 if (typeof this.options.customPlaceholder === "function") { 743 placeholder = this.options.customPlaceholder(placeholder, this.selectedCountryData); 744 } 745 this.telInput.attr("placeholder", placeholder); 746 } 747 }, 748 // called when the user selects a list item from the dropdown 749 _selectListItem: function(listItem) { 750 // update selected flag and active list item 751 this._setFlag(listItem.attr("data-country-code")); 752 this._closeDropdown(); 753 this._updateDialCode(listItem.attr("data-dial-code"), true); 754 // focus the input 755 this.telInput.focus(); 756 // fix for FF and IE11 (with nationalMode=false i.e. auto inserting dial code), who try to put the cursor at the beginning the first time 757 if (this.isGoodBrowser) { 758 var len = this.telInput.val().length; 759 this.telInput[0].setSelectionRange(len, len); 760 } 761 }, 762 // close the dropdown and unbind any listeners 763 _closeDropdown: function() { 764 this.countryList.addClass("hide"); 765 // update the arrow 766 this.selectedFlagInner.children(".iti-arrow").removeClass("up"); 767 // unbind key events 768 $(document).off(this.ns); 769 // unbind click-off-to-close 770 $("html").off(this.ns); 771 // unbind hover and click listeners 772 this.countryList.off(this.ns); 773 // remove menu from container 774 if (this.options.dropdownContainer) { 775 if (!this.isMobile) { 776 $(window).off("scroll" + this.ns); 777 } 778 this.dropdown.detach(); 779 } 780 }, 781 // check if an element is visible within it's container, else scroll until it is 782 _scrollTo: function(element, middle) { 783 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;
784 if (elementTop < containerTop) { 785 // scroll up 786 if (middle) { 787 newScrollTop -= middleOffset; 788 } 789 container.scrollTop(newScrollTop); 790 } else if (elementBottom > containerBottom) { 791 // scroll down 792 if (middle) { 793 newScrollTop += middleOffset; 794 } 795 var heightDifference = containerHeight - elementHeight; 796 container.scrollTop(newScrollTop - heightDifference); 797 } 798 }, 799 // replace any existing dial code with the new one 800 // Note: called from _selectListItem and setCountry 801 _updateDialCode: function(newDialCode, hasSelectedListItem) { 802 var inputVal = this.telInput.val(), newNumber; 803 // save having to pass this every time 804 newDialCode = "+" + newDialCode; 805 if (inputVal.charAt(0) == "+") { 806 // there's a plus so we're dealing with a replacement (doesn't matter if nationalMode or not) 807 var prevDialCode = this._getDialCode(inputVal); 808 if (prevDialCode) { 809 // current number contains a valid dial code, so replace it 810 newNumber = inputVal.replace(prevDialCode, newDialCode); 811 } else { 812 // current number contains an invalid dial code, so ditch it 813 // (no way to determine where the invalid dial code ends and the rest of the number begins) 814 newNumber = newDialCode; 815 } 816 } else if (this.options.nationalMode || this.options.separateDialCode) { 817 // don't do anything 818 return; 819 } else { 820 // nationalMode is disabled 821 if (inputVal) { 822 // there is an existing value with no dial code: prefix the new dial code 823 newNumber = newDialCode + inputVal; 824 } else if (hasSelectedListItem || !this.options.autoHideDialCode) { 825 // no existing value and either they've just selected a list item, or autoHideDialCode is disabled: insert new dial code 826 newNumber = newDialCode; 827 } else { 828 return; 829 } 830 } 831 this.telInput.val(newNumber); 832 }, 833 // try and extract a valid international dial code from a full telephone number 834 // Note: returns the raw string inc plus character and any whitespace/dots etc 835 _getDialCode: function(number) { 836 var dialCode = ""; 837 // only interested in international numbers (starting with a plus) 838 if (number.charAt(0) == "+") { 839 var numericChars = ""; 840 // iterate over chars 841 for (var i = 0; i < number.length; i++) { 842 var c = number.charAt(i); 843 // if char is number 844 if ($.isNumeric(c)) { 845 numericChars += c; 846 // if current numericChars make a valid dial code 847 if (this.countryCodes[numericChars]) { 848 // store the actual raw string (useful for matching later) 849 dialCode = number.substr(0, i + 1); 850 } 851 // longest dial code is 4 chars 852 if (numericChars.length == 4) { 853 break; 854 } 855 } 856 } 857 } 858 return dialCode; 859 }, 860 // get the input val, adding the dial code if separateDialCode is enabled 861 _getFullNumber: function() { 862 var prefix = this.options.separateDialCode ? "+" + this.selectedCountryData.dialCode : ""; 863 return prefix + this.telInput.val(); 864 }, 865 // remove the dial code if separateDialCode is enabled 866 _beforeSetNumber: function(number) { 867 if (this.options.separateDialCode) { 868 var dialCode = this._getDialCode(number); 869 if (dialCode) { 870 // US dialCode is "+1", which is what we want 871 // CA dialCode is "+1 123", which is wrong - should be "+1" (as it has multiple area codes) 872 // AS dialCode is "+1 684", which is what we want 873 // Solution: if the country has area codes, then revert to just the dial code 874 if (this.selectedCountryData.areaCodes !== null) { 875 dialCode = "+" + this.selectedCountryData.dialCode; 876 } 877 // 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 878 // NOTE: don't just trim all non-numerics as may want to preserve an open parenthesis etc 879 var start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length; 880 number = number.substr(start); 881 } 882 } 883 return this._cap(number); 884 }, 885 /******************** 886 * PUBLIC METHODS 887 ********************/ 888 // this is called when the geoip call returns 889 handleAutoCountry: function() { 890 if (this.options.initialCountry === "auto") { 891 // we must set this even if there is an initial val in the input: in case the initial val is invali
891d and they delete it - they should see their auto country 892 this.defaultCountry = $.fn[pluginName].autoCountry; 893 // if there's no initial value in the input, then update the flag 894 if (!this.telInput.val()) { 895 this.setCountry(this.defaultCountry); 896 } 897 this.autoCountryDeferred.resolve(); 898 } 899 }, 900 // remove plugin 901 destroy: function() { 902 if (this.allowDropdown) { 903 // make sure the dropdown is closed (and unbind listeners) 904 this._closeDropdown(); 905 // click event to open dropdown 906 this.selectedFlagInner.parent().off(this.ns); 907 // label click hack 908 this.telInput.closest("label").off(this.ns); 909 } 910 // unbind all events: key events, and focus/blur events if autoHideDialCode=true 911 this.telInput.off(this.ns); 912 // remove markup (but leave the original input) 913 var container = this.telInput.parent(); 914 container.before(this.telInput).remove(); 915 }, 916 // get the extension from the current number 917 getExtension: function() { 918 if (window.intlTelInputUtils) { 919 return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2); 920 } 921 return ""; 922 }, 923 // format the number to the given format 924 getNumber: function(format) { 925 if (window.intlTelInputUtils) { 926 return intlTelInputUtils.formatNumber(this._getFullNumber(), this.selectedCountryData.iso2, format); 927 } 928 return ""; 929 }, 930 // get the type of the entered number e.g. landline/mobile 931 getNumberType: function() { 932 if (window.intlTelInputUtils) { 933 return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2); 934 } 935 return -99; 936 }, 937 // get the country data for the currently selected flag 938 getSelectedCountryData: function() { 939 // if this is undefined, the plugin will return it's instance instead, so in that case an empty object makes more sense 940 return this.selectedCountryData || {}; 941 }, 942 // get the validation error 943 getValidationError: function() { 944 if (window.intlTelInputUtils) { 945 return intlTelInputUtils.getValidationError(this._getFullNumber(), this.selectedCountryData.iso2); 946 } 947 return -99; 948 }, 949 // validate the input val - assumes the global function isValidNumber (from utilsScript) 950 isValidNumber: function() { 951 var val = $.trim(this._getFullNumber()), countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : ""; 952 return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null; 953 }, 954 // update the selected flag, and update the input val accordingly 955 setCountry: function(countryCode) { 956 countryCode = countryCode.toLowerCase(); 957 // check if already selected 958 if (!this.selectedFlagInner.hasClass(countryCode)) { 959 this._setFlag(countryCode); 960 this._updateDialCode(this.selectedCountryData.dialCode, false); 961 } 962 }, 963 // set the input value and update the flag 964 // NOTE: format arg is for public method: to allow devs to format how they want 965 setNumber: function(number, format) { 966 // we must update the flag first, which updates this.selectedCountryData, which is used for formatting the number before displaying it 967 this._updateFlagFromNumber(number); 968 this._updateValFromNumber(number, $.isNumeric(format), format); 969 }, 970 // this is called when the utils request completes 971 handleUtils: function() { 972 // if the request was successful 973 if (window.intlTelInputUtils) { 974 // if there's an initial value in the input, then format it 975 if (this.telInput.val()) {
976 this._updateValFromNumber(this.telInput.val(), this.options.formatOnInit); 977 } 978 this._updatePlaceholder(); 979 } 980 this.utilsScriptDeferred.resolve(); 981 } 982 }; 983 // using https://github.com/jquery-boilerplate/jquery-boilerplate/wiki/Extending-jQuery-Boilerplate 984 // (adapted to allow public functions) 985 $.fn[pluginName] = function(options) { 986 var args = arguments; 987 // Is the first parameter an object (options), or was omitted, 988 // instantiate a new instance of the plugin. 989 if (options === undefined || typeof options === "object") { 990 // collect all of the deferred objects for all instances created with this selector 991 var deferreds = []; 992 this.each(function() { 993 if (!$.data(this, "plugin_" + pluginName)) { 994 var instance = new Plugin(this, options); 995 var instanceDeferreds = instance._init(); 996 // we now have 2 deffereds: 1 for auto country, 1 for utils script 997 deferreds.push(instanceDeferreds[0]); 998 deferreds.push(instanceDeferreds[1]); 999 $.data(this, "plugin_" + pluginName, instance); 1000 } 1001 }); 1002 // return the promise from the "master" deferred object that tracks all the others 1003 return $.when.apply(null, deferreds); 1004 } else if (typeof options === "string" && options[0] !== "_") { 1005 // If the first parameter is a string and it doesn't start 1006 // with an underscore or "contains" the `init`-function, 1007 // treat this as a call to a public method. 1008 // Cache the method call to make it possible to return a value 1009 var returns; 1010 this.each(function() { 1011 var instance = $.data(this, "plugin_" + pluginName); 1012 // Tests that there's already a plugin-instance 1013 // and checks that the requested public method exists 1014 if (instance instanceof Plugin && typeof instance[options] === "function") { 1015 // Call the method of our plugin instance, 1016 // and pass it the supplied arguments. 1017 returns = instance[options].apply(instance, Array.prototype.slice.call(args, 1)); 1018 } 1019 // Allow instances to be destroyed via the 'destroy' method 1020 if (options === "destroy") { 1021 $.data(this, "plugin_" + pluginName, null); 1022 } 1023 }); 1024 // If the earlier cached method gives a value back return the value, 1025 // otherwise return this to preserve chainability. 1026 return returns !== undefined ? returns : this; 1027 } 1028 }; 1029 /******************** 1030 * STATIC METHODS 1031 ********************/ 1032 // get the country data object 1033 $.fn[pluginName].getCountryData = function() { 1034 return allCountries; 1035 }; 1036 // load the utils script 1037 $.fn[pluginName].loadUtils = function(path, utilsScriptDeferred) { 1038 if (!$.fn[pluginName].loadedUtilsScript) { 1039 // 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) 1040 $.fn[pluginName].loadedUtilsScript = true; 1041 // dont use $.getScript as it prevents caching 1042 $.ajax({ 1043 url: path, 1044 complete: function() { 1045 // tell all instances that the utils request is complete 1046 $(".intl-tel-input input").intlTelInput("handleUtils"); 1047 }, 1048 dataType: "script", 1049 cache: true 1050 }); 1051 } else if (utilsScriptDeferred) { 1052 utilsScriptDeferred.resolve(); 1053 } 1054 }; 1055 // version 1056 $.fn[pluginName].version = "8.4.7"; 1057 // Tell JSHint to ignore this warning: "character may get silently deleted by one or more browsers"
1058 // jshint -W100 1059 // Array of country objects for the flag dropdown. 1060 // Each contains a name, country code (ISO 3166-1 alpha-2) and dial code. 1061 // Originally from https://github.com/mledoze/countries 1062 // then with a couple of manual re-arrangements to be alphabetical 1063 // then changed Kazakhstan from +76 to +7 1064 // and Vatican City from +379 to +39 (see issue 50) 1065 // and Caribean Netherlands from +5997 to +599 1066 // and Curacao from +5999 to +599 1067 // Removed: Kosovo, Pitcairn Islands, South Georgia 1068 // UPDATE Sept 12th 2015 1069 // List of regions that have iso2 country codes, which I have chosen to omit: 1070 // (based on this information: https://en.wikipedia.org/wiki/List_of_country_calling_codes) 1071 // AQ - Antarctica - all different country codes depending on which "base" 1072 // BV - Bouvet Island - no calling code 1073 // GS - South Georgia and the South Sandwich Islands - "inhospitable collection of islands" - same flag and calling code as Falkland Islands 1074 // HM - Heard Island and McDonald Islands - no calling code 1075 // PN - Pitcairn - tiny population (56), same calling code as New Zealand 1076 // TF - French Southern Territories - no calling code 1077 // UM - United States Minor Outlying Islands - no calling code 1078 // UPDATE the criteria of supported countries or territories (see issue 297) 1079 // Have an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 1080 // Have a country calling code: https://en.wikipedia.org/wiki/List_of_country_calling_codes 1081 // Have a flag 1082 // Must be supported by libphonenumber: https://github.com/googlei18n/libphonenumber 1083 // Update: converted objects to arrays to save bytes! 1084 // Update: added "priority" for countries with the same dialCode as others 1085 // Update: added array of area codes for countries with the same dialCode as others 1086 // So each country array has the following information: 1087 // [ 1088 // Country name, 1089 // iso2 code, 1090 // International dial code, 1091 // Order (if >1 country with same dial code), 1092 // Area codes (if >1 country with same dial code) 1093 // ] 1094 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
1094aat)", "gl", "299" ], [ "Grenada", "gd", "1473" ], [ "Guadeloupe", "gp", "590", 0 ], [ "Guam", "gu", "1671" ], [ "Guatemala", "gt", "502" ], [ "Guernsey", "gg", "44", 1 ], [ "Guinea (Guinée)", "gn", "224" ], [ "Guinea-Bissau (Guiné Bissau)", "gw", "245" ], [ "Guyana", "gy", "592" ], [ "Haiti", "ht", "509" ], [ "Honduras", "hn", "504" ], [ "Hong Kong (馿¸¯)", "hk", "852" ], [ "Hungary (Magyarország)", "hu", "36" ], [ "Iceland (Ãsland)", "is", "354" ], [ "India (à¤à¤¾à¤°à¤¤)", "in", "91" ], [ "Indonesia", "id", "62" ], [ "Iran (â«Ø§ÛراÙâ¬â)", "ir", "98" ], [ "Iraq (â«Ø§ÙعراÙâ¬â)", "iq", "964" ], [ "Ireland", "ie", "353" ], [ "Isle of Man", "im", "44", 2 ], [ "Israel (â«×שר××â¬â)", "il", "972" ], [ "Italy (Italia)", "it", "39", 0 ], [ "Jamaica", "jm", "1876" ], [ "Japan (æ¥æ¬)", "jp", "81" ], [ "Jersey", "je", "44", 3 ], [ "Jordan (â«Ø§ÙأردÙâ¬â)", "jo", "962" ], [ "Kazakhstan (ÐÐ°Ð·Ð°Ñ ÑÑан)", "kz", "7", 1 ], [ "Kenya", "ke", "254" ], [ "Kiribati", "ki", "686" ], [ "Kuwait (â«Ø§ÙÙÙÙØªâ¬â)", "kw", "965" ], [ "Kyrgyzstan (ÐÑÑгÑзÑÑан)", "kg", "996" ], [ "Laos (ລາວ)", "la", "856" ], [ "Latvia (Latvija)", "lv", "371" ], [ "Lebanon (â«ÙØ¨ÙØ§Ùâ¬â)", "lb", "961" ], [ "Lesotho", "ls", "266" ], [ "Liberia", "lr", "231" ], [ "Libya (â«ÙÙØ¨Ùاâ¬â)", "ly", "218" ], [ "Liechtenstein", "li", "423" ], [ "Lithuania (Lietuva)", "lt", "370" ], [ "Luxembourg", "lu", "352" ], [ "Macau (æ¾³é)", "mo", "853" ], [ "Macedonia (FYROM) (ÐакедониÑа)", "mk", "389" ], [ "Madagascar (Madagasikara)", "mg", "261" ], [ "Malawi", "mw", "265" ], [ "Malaysia", "my", "60" ], [ "Maldives", "mv", "960" ], [ "Mali", "ml", "223" ], [ "Malta", "mt", "356" ], [ "Marshall Islands", "mh", "692" ], [ "Martinique", "mq", "596" ], [ "Mauritania (â«Ù ÙØ±ÙتاÙÙØ§â¬â)", "mr", "222" ], [ "Mauritius (Moris)", "mu", "230" ], [ "Mayotte", "yt", "262", 1 ], [ "Mexico (México)", "mx", "52" ], [ "Micronesia", "fm", "691" ], [ "Moldova (Republica Moldova)", "md", "373" ], [ "Monaco", "mc", "377" ], [ "Mongolia (Ðонгол)", "mn", "976" ], [ "Montenegro (Crna Gora)", "me", "382" ], [ "Montserrat", "ms", "1664" ], [ "Morocco (â«Ø§Ù٠غربâ¬â)", "ma", "212", 0 ], [ "Mozambique (Moçambique)", "mz", "258" ], [ "Myanmar (Burma) (áá¼ááºáá¬)", "mm", "95" ], [ "Namibia (Namibië)", "na", "264" ], [ "Nauru", "nr", "674" ], [ "Nepal (नà¥à¤ªà¤¾à¤²)", "np", "977" ], [ "Netherlands (Nederland)", "nl", "31" ], [ "New Caledonia (Nouvelle-Calédonie)", "nc", "687" ], [ "New Zealand", "nz", "64" ], [ "Nicaragua", "ni", "505" ], [ "Niger (Nijar)", "ne", "227" ], [ "Nigeria", "ng", "234" ], [ "Niue", "nu", "683" ], [ "Norfolk Island", "nf", "672" ], [ "North Korea (ì¡°ì 민주주ì ì¸ë¯¼ ê³µíêµ)", "kp", "850" ], [ "Northern Mariana Islands", "mp", "1670" ], [ "Norway (Norge)", "no", "47", 0 ], [ "Oman (â«Ø¹Ù٠اÙâ¬â)", "om", "968" ], [ "Pakistan (â«Ù¾Ø§Ú©Ø³ØªØ§Ùâ¬â)", "pk", "92" ], [ "Palau", "pw", "680" ], [ "Palestine (â«ÙÙØ³Ø·ÙÙâ¬â)", "ps", "970" ], [ "Panama (Panamá)", "pa", "507" ], [ "Papua New Guinea", "pg", "675" ], [ "Paraguay", "py", "595" ], [ "Peru (Perú)", "pe", "51" ], [ "Philippines", "ph", "63" ], [ "Poland (Polska)", "pl", "48" ], [ "Portugal", "pt", "351" ], [ "Puerto Rico", "pr", "1", 3, [ "787", "939" ] ], [ "Qatar (â«Ùطرâ¬â)", "qa", "974" ], [ "Réunion (La Réunion)", "re", "262", 0 ], [ "Romania (România)", "ro", "40" ], [ "Russia (РоÑÑиÑ)", "ru", "7", 0 ], [ "Rwanda", "rw", "250" ], [ "Saint Barthélemy (Saint-Barthélemy)", "bl", "590", 1 ], [ "Saint Helena", "sh", "290" ], [ "Saint Kitts and Nevis", "kn", "1869" ], [ "Saint Lucia", "lc", "1758" ], [ "Saint Martin (Saint-Martin (partie française))", "mf", "590", 2 ], [ "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)", "pm", "508" ], [ "Saint Vincent and the Grenadines", "vc", "1784" ], [ "Samoa", "ws", "685" ], [ "San Marino", "sm", "378" ], [ "São Tomé and PrÃncipe (São Tomé e PrÃncipe)", "st", "239" ], [ "Saudi Arabia (â«Ø§ÙÙ Ù ÙÙØ© Ø§ÙØ¹Ø±Ø¨ÙØ© Ø§ÙØ³Ø¹ÙØ¯ÙØ©â¬â)", "sa", "966" ], [ "Senegal (Sénégal)", "sn", "221" ], [ "Serbia (СÑбиÑа)", "rs", "381" ], [ "Seychelles", "sc", "248" ], [ "Sierra Leone", "sl", "232" ], [ "Singapore", "sg", "65" ], [ "Sint Maarten", "sx", "1721" ], [ "Slovakia (Slovensko)", "sk", "421" ], [ "Slovenia (Slovenija)", "si", "386" ], [ "Solomon Islands", "sb", "677" ], [ "Somalia (Soomaaliya)", "so", "252" ], [ "South Africa", "za", "27" ], [ "South Korea (ëí민êµ)", "kr", "82" ], [ "South Sudan (â«Ø¬ÙÙØ¨ Ø§ÙØ³ÙداÙâ¬â)", "ss", "211" ], [ "Spain (España)", "es", "34" ], [ "Sri Lanka (à·à·âර෠ලà¶à¶à·à·)", "lk", "94" ], [ "Sudan (â«Ø§ÙØ³ÙØ¯Ø§Ùâ¬â)", "sd", "249" ], [ "Suriname", "sr", "597" ], [ "Svalbard and Jan Mayen", "sj", "47", 1 ], [ "Swaziland", "sz", "268" ], [ "Sweden (Sverige)", "se", "46" ], [ "Switzerland (Schweiz)", "ch", "41" ], [ "Syria (â«Ø³ÙØ±ÙØ§â¬â)", "sy", "963" ], [ "Taiwan (å°ç£)", "tw", "886" ], [ "Tajikistan", "tj", "992" ], [ "Tanzania", "tz", "255" ], [ "Thailand (à¹à¸à¸¢)", "th", "66" ], [ "Timor-Leste", "tl", "670" ], [ "Togo", "tg", "228" ], [ "Tokelau", "tk", "690" ], [ "Tonga", "to", "676" ], [ "Trinidad and Tobago", "tt", "1868" ], [ "Tunisia (â«ØªÙÙØ³â¬â)", "tn", "216" ], [ "Turkey (Türkiye)", "tr", "90" ], [ "Turkmenistan", "tm", "993" ], [ "Turks and Caicos Islands", "tc", "1649" ], [ "Tuvalu", "tv", "688" ], [ "U.S. Virgin Islands", "vi", "1340" ], [ "Uganda", "ug", "256" ], [ "Ukraine (УкÑаÑна)", "ua", "380" ], [ "United Arab Emirates (â«Ø§Ùإ٠ارات Ø§ÙØ¹Ø±Ø¨ÙØ© اÙÙ ØªØØ¯Ø©â¬â)", "ae", "971" ], [ "United Kingdom", "gb", "44", 0 ], [ "United States", "us", "1", 0 ], [ "Uruguay", "uy", "598" ], [ "Uzbekistan (OÊ»zbekiston)", "uz", "998" ], [ "Vanuatu", "vu", "678" ], [ "Vatican City (Città del Vaticano)", "va", "39", 1 ], [ "Venezuela", "ve", "58" ], [ "Vietnam (Viá»t Nam)", "vn", "84" ], [ "Wallis and Futuna", "wf", "681" ], [ "Western Sahara (â«Ø§ÙØµØØ±Ø§Ø¡ Ø§ÙØºØ±Ø¨ÙØ©â¬â)", "eh", "212", 1 ], [ "Yemen (â«Ø§ÙÙÙ Ùâ¬â)", "ye", "967" ], [ "Zambia", "zm", "260" ], [ "Zimbabwe", "zw", "263" ], [ "à land Islands", "ax", "358", 1 ] ]; 1095 // loop over all of the countries above 1096 for (var i = 0; i < allCountries.length; i++) { 1097 var c = allCountries[i]; 1098 allCountries[i] = { 1099 name: c[0], 1100 iso2: c[1], 1101 dialCode: c[2], 1102 priority: c[3] || 0, 1103 areaCodes: c[4] || null 1104 }; 1105 } 1106});
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.