intl-tel-input 8.4.9 → 12.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8bcd2575cb0194eb84176b2a55ecd684d1de8af9
4
- data.tar.gz: f2bf5adf402d0b65fba2b774e12e1cb9bbaf0925
3
+ metadata.gz: d59d1c519ea21161d44646b3341bb13f8d55c962
4
+ data.tar.gz: 241eeb077d47ca1235bf840ca037d99721e0b989
5
5
  SHA512:
6
- metadata.gz: 1ccc162c8930296b36f301312f652094aeb5a2137ff2900efad9debf1b933354d6db2435012b678a3c82ab4cb4d1cd9d9b68ca3a2ffe836e859d6a6518bba772
7
- data.tar.gz: b739245a85d2290fe846394ec3ace310f386aae258285dcac545b2faf05a090234ae52d56df294af694da6806a091598190e627d8e89d3daf29673e0bd16809e
6
+ metadata.gz: c3205f7687bc0a0849d4e390c814220803168fb74de68201c1341f2fd237336fc5ab06400db80b29f3c30b853c68f9ccc6a1dfaf34096d75b9702e3af92c430b
7
+ data.tar.gz: 8029a8c0d46bd844ba744d01f64f2fc9f1d36dcd4417afc5927c78f84fbe45f84118ee7b6deec60a637afd869a94d05062656d5061d8f09ee2b974e4064080ce
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .DS_Store
2
- *.gem
2
+ Gemfile.lock
3
+ *.gem
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # International Telephone Input
2
2
 
3
- This gem packages the [intl-tel-input](https://github.com/Bluefieldscom/intl-tel-input) assets (JavaScripts, stylesheets, and images) for the Rails asset pipeline.
3
+ This gem packages the [intl-tel-input](https://github.com/jackocnr/intl-tel-input) assets (JavaScripts, stylesheets, and images) for the Rails asset pipeline.
4
4
 
5
5
  Check the original documentation here:
6
- [https://github.com/Bluefieldscom/intl-tel-input](https://github.com/Bluefieldscom/intl-tel-input)
6
+ [https://github.com/jackocnr/intl-tel-input](https://github.com/jackocnr/intl-tel-input)
7
7
 
8
8
  ## Installation
9
9
 
@@ -24,4 +24,4 @@ Also add to your application.css:
24
24
  /*
25
25
  *= require intl-tel-input
26
26
  */
27
- ```
27
+ ```
@@ -1,8 +1,9 @@
1
1
  /*
2
- * International Telephone Input v8.4.9
2
+ * International Telephone Input v12.0.1
3
3
  * https://github.com/jackocnr/intl-tel-input.git
4
4
  * Licensed under the MIT license
5
5
  */
6
+
6
7
  // wrap in UMD - see https://github.com/umdjs/umd/blob/master/jqueryPluginCommonjs.js
7
8
  (function(factory) {
8
9
  if (typeof define === "function" && define.amd) {
@@ -23,26 +24,28 @@
23
24
  allowDropdown: true,
24
25
  // if there is just a dial code in the input: remove it on blur, and re-add it on focus
25
26
  autoHideDialCode: true,
26
- // add or remove input placeholder with an example number for the selected country
27
- autoPlaceholder: true,
27
+ // add a placeholder in the input with an example number for the selected country
28
+ autoPlaceholder: "polite",
28
29
  // modify the auto placeholder
29
30
  customPlaceholder: null,
30
31
  // append menu to a specific element
31
32
  dropdownContainer: "",
32
33
  // don't display these countries
33
34
  excludeCountries: [],
34
- // format the input value during initialisation
35
- formatOnInit: true,
35
+ // format the input value during initialisation and on setNumber
36
+ formatOnDisplay: true,
36
37
  // geoIp lookup function
37
38
  geoIpLookup: null,
39
+ // inject a hidden input with this name, and on submit, populate it with the result of getNumber
40
+ hiddenInput: "",
38
41
  // initial country
39
42
  initialCountry: "",
40
43
  // don't insert international dial codes
41
44
  nationalMode: true,
42
- // number type to use for placeholders
43
- numberType: "MOBILE",
44
45
  // display only these countries
45
46
  onlyCountries: [],
47
+ // number type to use for placeholders
48
+ placeholderNumberType: "MOBILE",
46
49
  // the countries at the top of the list. defaults to united states and united kingdom
47
50
  preferredCountries: [ "us", "gb" ],
48
51
  // display the country dial code next to the selected flag so it's not part of the typed number
@@ -59,9 +62,10 @@
59
62
  Z: 90,
60
63
  SPACE: 32,
61
64
  TAB: 9
62
- };
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" ];
63
67
  // keep track of if the window.load event has fired as impossible to check after the fact
64
- $(window).load(function() {
68
+ $(window).on("load", function() {
65
69
  // UPDATE: use a public static field so we can fudge it in the tests
66
70
  $.fn[pluginName].windowLoaded = true;
67
71
  });
@@ -83,13 +87,11 @@
83
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)
84
88
  if (this.options.separateDialCode) {
85
89
  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
90
  }
89
91
  // we cannot just test screen size as some smartphones/website meta tags will report desktop resolutions
90
92
  // Note: for some reason jasmine breaks if you put this in the main Plugin function with the rest of these declarations
91
93
  // 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);
94
+ this.isMobile = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
93
95
  if (this.isMobile) {
94
96
  // trigger the mobile dropdown css
95
97
  $("body").addClass("iti-mobile");
@@ -102,6 +104,8 @@
102
104
  // Note: again, jasmine breaks when I put these in the Plugin function
103
105
  this.autoCountryDeferred = new $.Deferred();
104
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 = {};
105
109
  // process all the data: onlyCountries, excludeCountries, preferredCountries etc
106
110
  this._processCountryData();
107
111
  // generate the markup
@@ -135,34 +139,21 @@
135
139
  var index = priority || 0;
136
140
  this.countryCodes[dialCode][index] = iso2;
137
141
  },
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
142
  // process onlyCountries or excludeCountries array if present
154
143
  _processAllCountries: function() {
155
144
  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;
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;
160
150
  });
161
151
  } 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;
152
+ var lowerCaseExcludeCountries = this.options.excludeCountries.map(function(country) {
153
+ return country.toLowerCase();
154
+ });
155
+ this.countries = allCountries.filter(function(country) {
156
+ return lowerCaseExcludeCountries.indexOf(country.iso2) === -1;
166
157
  });
167
158
  } else {
168
159
  this.countries = allCountries;
@@ -256,6 +247,12 @@
256
247
  // a little hack so we don't break anything
257
248
  this.countryListItems = $();
258
249
  }
250
+ if (this.options.hiddenInput) {
251
+ this.hiddenInput = $("<input>", {
252
+ type: "hidden",
253
+ name: this.options.hiddenInput
254
+ }).insertBefore(this.telInput);
255
+ }
259
256
  },
260
257
  // add a country <li> to the countryList <ul> container
261
258
  _appendListItems: function(countries, className) {
@@ -284,18 +281,19 @@
284
281
  // 4. picking the first country
285
282
  _setInitialState: function() {
286
283
  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);
284
+ // 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
285
+ // 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
286
+ if (this._getDialCode(val) && (!this._isRegionlessNanp(val) || this.options.nationalMode && !this.options.initialCountry)) {
287
+ this._updateFlagFromNumber(val);
290
288
  } else if (this.options.initialCountry !== "auto") {
291
289
  // see if we should select a flag
292
290
  if (this.options.initialCountry) {
293
- this._setFlag(this.options.initialCountry, true);
291
+ this._setFlag(this.options.initialCountry.toLowerCase());
294
292
  } else {
295
293
  // no dial code and no initialCountry, so default to first in list
296
294
  this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2;
297
295
  if (!val) {
298
- this._setFlag(this.defaultCountry, true);
296
+ this._setFlag(this.defaultCountry);
299
297
  }
300
298
  }
301
299
  // if empty and no nationalMode and no autoHideDialCode then insert the default dial code
@@ -307,7 +305,7 @@
307
305
  // format
308
306
  if (val) {
309
307
  // this wont be run after _updateDialCode as that's only called if no val
310
- this._updateValFromNumber(val, this.options.formatOnInit);
308
+ this._updateValFromNumber(val);
311
309
  }
312
310
  },
313
311
  // initialise the main event listeners: input keyup, and click selected flag
@@ -319,6 +317,19 @@
319
317
  if (this.options.allowDropdown) {
320
318
  this._initDropdownListeners();
321
319
  }
320
+ if (this.hiddenInput) {
321
+ this._initHiddenInputListener();
322
+ }
323
+ },
324
+ // update hidden input on form submit
325
+ _initHiddenInputListener: function() {
326
+ var that = this;
327
+ var form = this.telInput.closest("form");
328
+ if (form.length) {
329
+ form.submit(function() {
330
+ that.hiddenInput.val(that.getNumber());
331
+ });
332
+ }
322
333
  },
323
334
  // initialise the dropdown listeners
324
335
  _initDropdownListeners: function() {
@@ -371,7 +382,7 @@
371
382
  $.fn[pluginName].loadUtils(this.options.utilsScript, this.utilsScriptDeferred);
372
383
  } else {
373
384
  // wait until the load event so we don't block any other requests e.g. the flags image
374
- $(window).load(function() {
385
+ $(window).on("load", function() {
375
386
  $.fn[pluginName].loadUtils(that.options.utilsScript, that.utilsScriptDeferred);
376
387
  });
377
388
  }
@@ -387,11 +398,6 @@
387
398
  // perform the geo ip lookup
388
399
  _loadAutoCountry: function() {
389
400
  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
401
  // 3 options:
396
402
  // 1) already loaded (we're done)
397
403
  // 2) not already started loading (start)
@@ -404,11 +410,6 @@
404
410
  if (typeof this.options.geoIpLookup === "function") {
405
411
  this.options.geoIpLookup(function(countryCode) {
406
412
  $.fn[pluginName].autoCountry = countryCode.toLowerCase();
407
- if (window.Cookies) {
408
- Cookies.set("itiAutoCountry", $.fn[pluginName].autoCountry, {
409
- path: "/"
410
- });
411
- }
412
413
  // tell all instances the auto country is ready
413
414
  // TODO: this should just be the current instances
414
415
  // 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.
@@ -425,13 +426,17 @@
425
426
  // update flag on keyup
426
427
  // (keep this listener separate otherwise the setTimeout breaks all the tests)
427
428
  this.telInput.on("keyup" + this.ns, function() {
428
- that._updateFlagFromNumber(that.telInput.val());
429
+ if (that._updateFlagFromNumber(that.telInput.val())) {
430
+ that._triggerCountryChange();
431
+ }
429
432
  });
430
433
  // 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() {
434
+ this.telInput.on("cut" + this.ns + " paste" + this.ns, function() {
432
435
  // hack because "paste" event is fired before input is updated
433
436
  setTimeout(function() {
434
- that._updateFlagFromNumber(that.telInput.val());
437
+ if (that._updateFlagFromNumber(that.telInput.val())) {
438
+ that._triggerCountryChange();
439
+ }
435
440
  });
436
441
  });
437
442
  },
@@ -472,20 +477,29 @@
472
477
  });
473
478
  }
474
479
  });
475
- // on blur: if just a dial code then remove it
480
+ // on blur or form submit: if just a dial code then remove it
481
+ var form = this.telInput.prop("form");
482
+ if (form) {
483
+ $(form).on("submit" + this.ns, function() {
484
+ that._removeEmptyDialCode();
485
+ });
486
+ }
476
487
  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);
488
+ that._removeEmptyDialCode();
487
489
  });
488
490
  },
491
+ _removeEmptyDialCode: function() {
492
+ var value = this.telInput.val(), startsPlus = value.charAt(0) == "+";
493
+ if (startsPlus) {
494
+ var numeric = this._getNumeric(value);
495
+ // if just a plus, or if just a dial code
496
+ if (!numeric || this.selectedCountryData.dialCode == numeric) {
497
+ this.telInput.val("");
498
+ }
499
+ }
500
+ // remove the keypress listener we added on focus
501
+ this.telInput.off("keypress.plus" + this.ns);
502
+ },
489
503
  // extract the numeric digits from the given string
490
504
  _getNumeric: function(s) {
491
505
  return s.replace(/\D/g, "");
@@ -503,6 +517,7 @@
503
517
  this._bindDropdownListeners();
504
518
  // update the arrow
505
519
  this.selectedFlagInner.children(".iti-arrow").addClass("up");
520
+ this.telInput.trigger("open:countrydropdown");
506
521
  },
507
522
  // decide where to position dropdown (depends on position within viewport, and scroll)
508
523
  _setDropdownPosition: function() {
@@ -626,11 +641,9 @@
626
641
  },
627
642
  // update the input's value to the given val (format first if possible)
628
643
  // 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
- }
644
+ _updateValFromNumber: function(number) {
645
+ if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) {
646
+ var format = !this.options.separateDialCode && (this.options.nationalMode || number.charAt(0) != "+") ? intlTelInputUtils.numberFormat.NATIONAL : intlTelInputUtils.numberFormat.INTERNATIONAL;
634
647
  number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format);
635
648
  }
636
649
  number = this._beforeSetNumber(number);
@@ -638,22 +651,26 @@
638
651
  },
639
652
  // check if need to select a new flag based on the given number
640
653
  // Note: called from _setInitialState, keyup handler, setNumber
641
- _updateFlagFromNumber: function(number, isInit) {
654
+ _updateFlagFromNumber: function(number) {
642
655
  // 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
656
  // 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) != "+") {
657
+ if (number && this.options.nationalMode && this.selectedCountryData.dialCode == "1" && number.charAt(0) != "+") {
645
658
  if (number.charAt(0) != "1") {
646
659
  number = "1" + number;
647
660
  }
648
661
  number = "+" + number;
649
662
  }
650
663
  // try and extract valid dial code from input
651
- var dialCode = this._getDialCode(number), countryCode = null;
664
+ var dialCode = this._getDialCode(number), countryCode = null, numeric = this._getNumeric(number);
652
665
  if (dialCode) {
653
666
  // 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)) {
667
+ 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
668
+ isNanpAreaCode = dialCode == "+1" && numeric.length >= 4, nanpSelected = this.selectedCountryData.dialCode == "1";
669
+ // only update the flag if:
670
+ // A) NOT (we currently have a NANP flag selected, and the number is a regionlessNanp)
671
+ // AND
672
+ // 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)
673
+ if (!(nanpSelected && this._isRegionlessNanp(numeric)) && (!alreadySelected || isNanpAreaCode)) {
657
674
  // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first non-empty index
658
675
  for (var j = 0; j < countryCodes.length; j++) {
659
676
  if (countryCodes[j]) {
@@ -662,7 +679,7 @@
662
679
  }
663
680
  }
664
681
  }
665
- } else if (number.charAt(0) == "+" && this._getNumeric(number).length) {
682
+ } else if (number.charAt(0) == "+" && numeric.length) {
666
683
  // invalid dial code, so empty
667
684
  // Note: use getNumeric here because the number has not been formatted yet, so could contain bad chars
668
685
  countryCode = "";
@@ -671,12 +688,18 @@
671
688
  countryCode = this.defaultCountry;
672
689
  }
673
690
  if (countryCode !== null) {
674
- this._setFlag(countryCode, isInit);
691
+ return this._setFlag(countryCode);
675
692
  }
693
+ return false;
676
694
  },
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;
695
+ // check if the given number is a regionless NANP number (expects the number to contain an international dial code)
696
+ _isRegionlessNanp: function(number) {
697
+ var numeric = this._getNumeric(number);
698
+ if (numeric.charAt(0) == "1") {
699
+ var areaCode = numeric.substr(1, 3);
700
+ return $.inArray(areaCode, regionlessNanpNumbers) > -1;
701
+ }
702
+ return false;
680
703
  },
681
704
  // remove highlighting from other list items and highlight the given item
682
705
  _highlightListItem: function(listItem) {
@@ -700,8 +723,8 @@
700
723
  },
701
724
  // select the given flag, update the placeholder and the active list item
702
725
  // Note: called from _setInitialState, _updateFlagFromNumber, _selectListItem, setCountry
703
- _setFlag: function(countryCode, isInit) {
704
- var prevCountry = this.selectedCountryData && this.selectedCountryData.iso2 ? this.selectedCountryData : {};
726
+ _setFlag: function(countryCode) {
727
+ var prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {};
705
728
  // do this first as it will throw an error and stop if countryCode is invalid
706
729
  this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {};
707
730
  // update the defaultCountry - we only need the iso2 from now on, so just store that
@@ -729,15 +752,14 @@
729
752
  if (countryCode) {
730
753
  this.countryListItems.find(".iti-flag." + countryCode).first().closest(".country").addClass("active");
731
754
  }
732
- // on change flag, trigger a custom event
733
- if (!isInit && prevCountry.iso2 !== countryCode) {
734
- this.telInput.trigger("countrychange", this.selectedCountryData);
735
- }
755
+ // return if the flag has changed or not
756
+ return prevCountry.iso2 !== countryCode;
736
757
  },
737
758
  // update the input placeholder to an example number from the currently selected country
738
759
  _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) : "";
760
+ var shouldSetPlaceholder = this.options.autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && (this.options.autoPlaceholder === true || this.options.autoPlaceholder === "polite");
761
+ if (window.intlTelInputUtils && shouldSetPlaceholder) {
762
+ var numberType = intlTelInputUtils.numberType[this.options.placeholderNumberType], placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, this.options.nationalMode, numberType) : "";
741
763
  placeholder = this._beforeSetNumber(placeholder);
742
764
  if (typeof this.options.customPlaceholder === "function") {
743
765
  placeholder = this.options.customPlaceholder(placeholder, this.selectedCountryData);
@@ -748,16 +770,19 @@
748
770
  // called when the user selects a list item from the dropdown
749
771
  _selectListItem: function(listItem) {
750
772
  // update selected flag and active list item
751
- this._setFlag(listItem.attr("data-country-code"));
773
+ var flagChanged = this._setFlag(listItem.attr("data-country-code"));
752
774
  this._closeDropdown();
753
775
  this._updateDialCode(listItem.attr("data-dial-code"), true);
754
776
  // focus the input
755
777
  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
778
+ // 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
757
779
  if (this.isGoodBrowser) {
758
780
  var len = this.telInput.val().length;
759
781
  this.telInput[0].setSelectionRange(len, len);
760
782
  }
783
+ if (flagChanged) {
784
+ this._triggerCountryChange();
785
+ }
761
786
  },
762
787
  // close the dropdown and unbind any listeners
763
788
  _closeDropdown: function() {
@@ -777,6 +802,7 @@
777
802
  }
778
803
  this.dropdown.detach();
779
804
  }
805
+ this.telInput.trigger("close:countrydropdown");
780
806
  },
781
807
  // check if an element is visible within it's container, else scroll until it is
782
808
  _scrollTo: function(element, middle) {
@@ -859,8 +885,17 @@
859
885
  },
860
886
  // get the input val, adding the dial code if separateDialCode is enabled
861
887
  _getFullNumber: function() {
862
- var prefix = this.options.separateDialCode ? "+" + this.selectedCountryData.dialCode : "";
863
- return prefix + this.telInput.val();
888
+ 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
889
+ normalizedVal = numericVal.charAt(0) == "1" ? numericVal : "1" + numericVal;
890
+ if (this.options.separateDialCode) {
891
+ prefix = "+" + dialCode;
892
+ } else if (val.charAt(0) != "+" && val.charAt(0) != "1" && dialCode && dialCode.charAt(0) == "1" && dialCode.length == 4 && dialCode != normalizedVal.substr(0, 4)) {
893
+ // if the user has entered a national NANP number, then ensure it includes the full dial code / area code
894
+ prefix = dialCode.substr(1);
895
+ } else {
896
+ prefix = "";
897
+ }
898
+ return prefix + val;
864
899
  },
865
900
  // remove the dial code if separateDialCode is enabled
866
901
  _beforeSetNumber: function(number) {
@@ -882,9 +917,13 @@
882
917
  }
883
918
  return this._cap(number);
884
919
  },
885
- /********************
886
- * PUBLIC METHODS
887
- ********************/
920
+ // trigger the 'countrychange' event
921
+ _triggerCountryChange: function() {
922
+ this.telInput.trigger("countrychange", this.selectedCountryData);
923
+ },
924
+ /**************************
925
+ * SECRET PUBLIC METHODS
926
+ **************************/
888
927
  // this is called when the geoip call returns
889
928
  handleAutoCountry: function() {
890
929
  if (this.options.initialCountry === "auto") {
@@ -897,6 +936,21 @@
897
936
  this.autoCountryDeferred.resolve();
898
937
  }
899
938
  },
939
+ // this is called when the utils request completes
940
+ handleUtils: function() {
941
+ // if the request was successful
942
+ if (window.intlTelInputUtils) {
943
+ // if there's an initial value in the input, then format it
944
+ if (this.telInput.val()) {
945
+ this._updateValFromNumber(this.telInput.val());
946
+ }
947
+ this._updatePlaceholder();
948
+ }
949
+ this.utilsScriptDeferred.resolve();
950
+ },
951
+ /********************
952
+ * PUBLIC METHODS
953
+ ********************/
900
954
  // remove plugin
901
955
  destroy: function() {
902
956
  if (this.allowDropdown) {
@@ -907,6 +961,13 @@
907
961
  // label click hack
908
962
  this.telInput.closest("label").off(this.ns);
909
963
  }
964
+ // unbind submit event handler on form
965
+ if (this.options.autoHideDialCode) {
966
+ var form = this.telInput.prop("form");
967
+ if (form) {
968
+ $(form).off(this.ns);
969
+ }
970
+ }
910
971
  // unbind all events: key events, and focus/blur events if autoHideDialCode=true
911
972
  this.telInput.off(this.ns);
912
973
  // remove markup (but leave the original input)
@@ -936,8 +997,7 @@
936
997
  },
937
998
  // get the country data for the currently selected flag
938
999
  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 || {};
1000
+ return this.selectedCountryData;
941
1001
  },
942
1002
  // get the validation error
943
1003
  getValidationError: function() {
@@ -958,26 +1018,17 @@
958
1018
  if (!this.selectedFlagInner.hasClass(countryCode)) {
959
1019
  this._setFlag(countryCode);
960
1020
  this._updateDialCode(this.selectedCountryData.dialCode, false);
1021
+ this._triggerCountryChange();
961
1022
  }
962
1023
  },
963
1024
  // 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) {
1025
+ setNumber: function(number) {
966
1026
  // 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();
1027
+ var flagChanged = this._updateFlagFromNumber(number);
1028
+ this._updateValFromNumber(number);
1029
+ if (flagChanged) {
1030
+ this._triggerCountryChange();
979
1031
  }
980
- this.utilsScriptDeferred.resolve();
981
1032
  }
982
1033
  };
983
1034
  // using https://github.com/jquery-boilerplate/jquery-boilerplate/wiki/Extending-jQuery-Boilerplate
@@ -1040,6 +1091,7 @@
1040
1091
  $.fn[pluginName].loadedUtilsScript = true;
1041
1092
  // dont use $.getScript as it prevents caching
1042
1093
  $.ajax({
1094
+ type: "GET",
1043
1095
  url: path,
1044
1096
  complete: function() {
1045
1097
  // tell all instances that the utils request is complete
@@ -1052,46 +1104,25 @@
1052
1104
  utilsScriptDeferred.resolve();
1053
1105
  }
1054
1106
  };
1107
+ // default options
1108
+ $.fn[pluginName].defaults = defaults;
1055
1109
  // version
1056
- $.fn[pluginName].version = "8.4.9";
1057
- // Tell JSHint to ignore this warning: "character may get silently deleted by one or more browsers"
1058
- // jshint -W100
1110
+ $.fn[pluginName].version = "12.0.1";
1059
1111
  // 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:
1112
+ // Here is the criteria for the plugin to support a given country/territory
1113
+ // - It has an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
1114
+ // - 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
1115
+ // - It has a flag in the region-flags project: https://github.com/behdad/region-flags/tree/gh-pages/png
1116
+ // - It is supported by libphonenumber (it must be listed on this page): https://github.com/googlei18n/libphonenumber/blob/master/resources/ShortNumberMetadata.xml
1117
+ // Each country array has the following information:
1087
1118
  // [
1088
1119
  // Country name,
1089
1120
  // iso2 code,
1090
1121
  // International dial code,
1091
1122
  // Order (if >1 country with same dial code),
1092
- // Area codes (if >1 country with same dial code)
1123
+ // Area codes
1093
1124
  // ]
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 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" ], [ "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 ] ];
1125
+ 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 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 (‫عُمان‬‎)", "om", "968" ], [ "Pakistan (‫پاکستان‬‎)", "pk", "92" ], [ "Palau", "pw", "680" ], [ "Palestine (‫فلسطين‬‎)", "ps", "970" ], [ "Panama (Panamá)", "pa", "507" ], [ "Papua New Guinea", "pg", "675" ], [ "Paraguay", "py", "595" ], [ "Peru (Perú)", "pe", "51" ], [ "Philippines", "ph", "63" ], [ "Poland (Polska)", "pl", "48" ], [ "Portugal", "pt", "351" ], [ "Puerto Rico", "pr", "1", 3, [ "787", "939" ] ], [ "Qatar (‫قطر‬‎)", "qa", "974" ], [ "Réunion (La Réunion)", "re", "262", 0 ], [ "Romania (România)", "ro", "40" ], [ "Russia (Россия)", "ru", "7", 0 ], [ "Rwanda", "rw", "250" ], [ "Saint Barthélemy", "bl", "590", 1 ], [ "Saint Helena", "sh", "290" ], [ "Saint Kitts and Nevis", "kn", "1869" ], [ "Saint Lucia", "lc", "1758" ], [ "Saint Martin (Saint-Martin (partie française))", "mf", "590", 2 ], [ "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)", "pm", "508" ], [ "Saint Vincent and the Grenadines", "vc", "1784" ], [ "Samoa", "ws", "685" ], [ "San Marino", "sm", "378" ], [ "São Tomé and Príncipe (São Tomé e Príncipe)", "st", "239" ], [ "Saudi Arabia (‫المملكة العربية السعودية‬‎)", "sa", "966" ], [ "Senegal (Sénégal)", "sn", "221" ], [ "Serbia (Србија)", "rs", "381" ], [ "Seychelles", "sc", "248" ], [ "Sierra Leone", "sl", "232" ], [ "Singapore", "sg", "65" ], [ "Sint Maarten", "sx", "1721" ], [ "Slovakia (Slovensko)", "sk", "421" ], [ "Slovenia (Slovenija)", "si", "386" ], [ "Solomon Islands", "sb", "677" ], [ "Somalia (Soomaaliya)", "so", "252" ], [ "South Africa", "za", "27" ], [ "South Korea (대한민국)", "kr", "82" ], [ "South Sudan (‫جنوب السودان‬‎)", "ss", "211" ], [ "Spain (España)", "es", "34" ], [ "Sri Lanka (ශ්‍රී ලංකාව)", "lk", "94" ], [ "Sudan (‫السودان‬‎)", "sd", "249" ], [ "Suriname", "sr", "597" ], [ "Svalbard and Jan Mayen", "sj", "47", 1 ], [ "Swaziland", "sz", "268" ], [ "Sweden (Sverige)", "se", "46" ], [ "Switzerland (Schweiz)", "ch", "41" ], [ "Syria (‫سوريا‬‎)", "sy", "963" ], [ "Taiwan (台灣)", "tw", "886" ], [ "Tajikistan", "tj", "992" ], [ "Tanzania", "tz", "255" ], [ "Thailand (ไทย)", "th", "66" ], [ "Timor-Leste", "tl", "670" ], [ "Togo", "tg", "228" ], [ "Tokelau", "tk", "690" ], [ "Tonga", "to", "676" ], [ "Trinidad and Tobago", "tt", "1868" ], [ "Tunisia (‫تونس‬‎)", "tn", "216" ], [ "Turkey (Türkiye)", "tr", "90" ], [ "Turkmenistan", "tm", "993" ], [ "Turks and Caicos Islands", "tc", "1649" ], [ "Tuvalu", "tv", "688" ], [ "U.S. Virgin Islands", "vi", "1340" ], [ "Uganda", "ug", "256" ], [ "Ukraine (Україна)", "ua", "380" ], [ "United Arab Emirates (‫الإمارات العربية المتحدة‬‎)", "ae", "971" ], [ "United Kingdom", "gb", "44", 0 ], [ "United States", "us", "1", 0 ], [ "Uruguay", "uy", "598" ], [ "Uzbekistan (Oʻzbekiston)", "uz", "998" ], [ "Vanuatu", "vu", "678" ], [ "Vatican City (Città del Vaticano)", "va", "39", 1 ], [ "Venezuela", "ve", "58" ], [ "Vietnam (Việt Nam)", "vn", "84" ], [ "Wallis and Futuna (Wallis-et-Futuna)", "wf", "681" ], [ "Western Sahara (‫الصحراء الغربية‬‎)", "eh", "212", 1 ], [ "Yemen (‫اليمن‬‎)", "ye", "967" ], [ "Zambia", "zm", "260" ], [ "Zimbabwe", "zw", "263" ], [ "Åland Islands", "ax", "358", 1 ] ];
1095
1126
  // loop over all of the countries above
1096
1127
  for (var i = 0; i < allCountries.length; i++) {
1097
1128
  var c = allCountries[i];
@@ -1103,4 +1134,4 @@
1103
1134
  areaCodes: c[4] || null
1104
1135
  };
1105
1136
  }
1106
- });
1137
+ });