intl-tel-input 18.0.3 → 18.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/.eslintrc +2 -8
  2. package/.vscode/settings.json +8 -0
  3. package/CHANGELOG.md +3 -0
  4. package/Gruntfile.js +0 -2
  5. package/README.md +24 -30
  6. package/build/css/intlTelInput.css +1 -1
  7. package/build/js/data.js +1 -1
  8. package/build/js/data.min.js +1 -1
  9. package/build/js/intlTelInput-jquery.js +213 -89
  10. package/build/js/intlTelInput-jquery.min.js +3 -3
  11. package/build/js/intlTelInput.js +213 -89
  12. package/build/js/intlTelInput.min.js +3 -3
  13. package/composer.json +1 -1
  14. package/demo.html +42 -43
  15. package/demo_rtl.html +21 -23
  16. package/grunt/template.js +2 -265
  17. package/package.json +4 -1
  18. package/src/css/intlTelInput.scss +1 -1
  19. package/src/js/intlTelInput.js +605 -341
  20. package/examples/css/countrySync.css +0 -10
  21. package/examples/css/isValidNumber.css +0 -12
  22. package/examples/css/prism.css +0 -126
  23. package/examples/gen/country-sync.html +0 -98
  24. package/examples/gen/default-country-ip.html +0 -62
  25. package/examples/gen/display-number.html +0 -47
  26. package/examples/gen/hidden-input.html +0 -54
  27. package/examples/gen/init-promise.html +0 -66
  28. package/examples/gen/is-valid-number.html +0 -86
  29. package/examples/gen/js/countrySync.js +0 -31
  30. package/examples/gen/js/defaultCountryIp.js +0 -11
  31. package/examples/gen/js/displayNumber.js +0 -4
  32. package/examples/gen/js/hiddenInput.js +0 -5
  33. package/examples/gen/js/initPromise.js +0 -9
  34. package/examples/gen/js/isValidNumber.js +0 -37
  35. package/examples/gen/js/modifyCountryData.js +0 -11
  36. package/examples/gen/js/multipleInstances.js +0 -13
  37. package/examples/gen/js/nationalMode.js +0 -18
  38. package/examples/gen/js/onlyCountriesEurope.js +0 -8
  39. package/examples/gen/modify-country-data.html +0 -52
  40. package/examples/gen/multiple-instances.html +0 -60
  41. package/examples/gen/national-mode.html +0 -63
  42. package/examples/gen/only-countries-europe.html +0 -49
  43. package/examples/js/countrySync.js.ejs +0 -31
  44. package/examples/js/defaultCountryIp.js.ejs +0 -11
  45. package/examples/js/displayNumber.js.ejs +0 -4
  46. package/examples/js/hiddenInput.js.ejs +0 -5
  47. package/examples/js/initPromise.js.ejs +0 -9
  48. package/examples/js/isValidNumber.js.ejs +0 -37
  49. package/examples/js/modifyCountryData.js.ejs +0 -11
  50. package/examples/js/multipleInstances.js.ejs +0 -13
  51. package/examples/js/nationalMode.js.ejs +0 -18
  52. package/examples/js/onlyCountriesEurope.js.ejs +0 -8
  53. package/examples/js/prism.js +0 -11
  54. package/examples/partials/countrySync.html +0 -13
  55. package/examples/partials/defaultCountryIp.html +0 -5
  56. package/examples/partials/displayNumber.html +0 -1
  57. package/examples/partials/hiddenInput.html +0 -4
  58. package/examples/partials/initPromise.html +0 -8
  59. package/examples/partials/isValidNumber.html +0 -3
  60. package/examples/partials/multipleInstances.html +0 -3
  61. package/examples/partials/nationalMode.html +0 -2
  62. package/examples/partials/simpleInput.html +0 -1
  63. package/examples/template.html.ejs +0 -43
@@ -1,5 +1,5 @@
1
1
  /*
2
- * International Telephone Input v18.0.3
2
+ * International Telephone Input v18.1.1
3
3
  * https://github.com/jackocnr/intl-tel-input.git
4
4
  * Licensed under the MIT license
5
5
  */
@@ -113,7 +113,9 @@
113
113
  return document.readyState === "complete";
114
114
  }
115
115
  };
116
- if (typeof window === "object") window.intlTelInputGlobals = intlTelInputGlobals;
116
+ if (typeof window === "object") {
117
+ window.intlTelInputGlobals = intlTelInputGlobals;
118
+ }
117
119
  // these vars persist through all instances of the plugin
118
120
  var id = 0;
119
121
  var defaults = {
@@ -142,7 +144,7 @@
142
144
  initialCountry: "",
143
145
  // localized country names e.g. { 'de': 'Deutschland' }
144
146
  localizedCountries: null,
145
- // deal with national numbers instead of international numbers
147
+ // national vs international formatting for numbers e.g. placeholders and displaying existing numbers
146
148
  nationalMode: true,
147
149
  // display only these countries
148
150
  onlyCountries: [],
@@ -152,6 +154,8 @@
152
154
  preferredCountries: [ "us", "gb" ],
153
155
  // display the country dial code next to the selected flag
154
156
  separateDialCode: false,
157
+ // option to hide the flags - must be used with separateDialCode, or allowDropdown=false
158
+ showFlags: true,
155
159
  // specify the path to the libphonenumber script to enable validation/formatting
156
160
  utilsScript: ""
157
161
  };
@@ -195,9 +199,19 @@
195
199
  value: function _init() {
196
200
  var _this2 = this;
197
201
  // if in nationalMode, do not insert dial codes
198
- if (this.options.nationalMode) this.options.autoInsertDialCode = false;
202
+ if (this.options.nationalMode) {
203
+ this.options.autoInsertDialCode = false;
204
+ }
199
205
  // if separateDialCode enabled, do not insert dial codes
200
- if (this.options.separateDialCode) this.options.autoInsertDialCode = false;
206
+ if (this.options.separateDialCode) {
207
+ this.options.autoInsertDialCode = false;
208
+ }
209
+ // force showFlags=true if there's a dropdown and we're not displaying the dial code,
210
+ // as otherwise you just have a down arrow on it's own which doesn't make sense
211
+ var forceShowFlags = this.options.allowDropdown && !this.options.separateDialCode;
212
+ if (!this.options.showFlags && forceShowFlags) {
213
+ this.options.showFlags = true;
214
+ }
201
215
  // we cannot just test screen size as some smartphones/website meta tags will report desktop
202
216
  // resolutions
203
217
  // Note: for some reason jasmine breaks if you put this in the main Plugin function with the
@@ -208,7 +222,9 @@
208
222
  // trigger the mobile dropdown css
209
223
  document.body.classList.add("iti-mobile");
210
224
  // on mobile, we want a full screen dropdown, so we must append it to the body
211
- if (!this.options.dropdownContainer) this.options.dropdownContainer = document.body;
225
+ if (!this.options.dropdownContainer) {
226
+ this.options.dropdownContainer = document.body;
227
+ }
212
228
  }
213
229
  // these promises get resolved when their individual requests complete
214
230
  // this way the dev can do something like iti.promise.then(...) to know when all requests are
@@ -252,7 +268,9 @@
252
268
  // process the preferredCountries
253
269
  this._processPreferredCountries();
254
270
  // translate countries according to localizedCountries option
255
- if (this.options.localizedCountries) this._translateCountriesByLocale();
271
+ if (this.options.localizedCountries) {
272
+ this._translateCountriesByLocale();
273
+ }
256
274
  // sort countries by name
257
275
  if (this.options.onlyCountries.length || this.options.localizedCountries) {
258
276
  this.countries.sort(this._countryNameSort);
@@ -269,7 +287,9 @@
269
287
  }
270
288
  // bail if we already have this country for this countryCode
271
289
  for (var i = 0; i < this.countryCodes[countryCode].length; i++) {
272
- if (this.countryCodes[countryCode][i] === iso2) return;
290
+ if (this.countryCodes[countryCode][i] === iso2) {
291
+ return;
292
+ }
273
293
  }
274
294
  // check for undefined as 0 is falsy
275
295
  var index = priority !== undefined ? priority : this.countryCodes[countryCode].length;
@@ -309,8 +329,12 @@
309
329
  }, {
310
330
  key: "_countryNameSort",
311
331
  value: function _countryNameSort(a, b) {
312
- if (a.name < b.name) return -1;
313
- if (a.name > b.name) return 1;
332
+ if (a.name < b.name) {
333
+ return -1;
334
+ }
335
+ if (a.name > b.name) {
336
+ return 1;
337
+ }
314
338
  return 0;
315
339
  }
316
340
  }, {
@@ -324,7 +348,9 @@
324
348
  // first: add dial codes
325
349
  for (var i = 0; i < this.countries.length; i++) {
326
350
  var c = this.countries[i];
327
- if (!this.dialCodes[c.dialCode]) this.dialCodes[c.dialCode] = true;
351
+ if (!this.dialCodes[c.dialCode]) {
352
+ this.dialCodes[c.dialCode] = true;
353
+ }
328
354
  this._addCountryCode(c.iso2, c.dialCode, c.priority);
329
355
  }
330
356
  // next: add area codes
@@ -359,17 +385,23 @@
359
385
  for (var i = 0; i < this.options.preferredCountries.length; i++) {
360
386
  var countryCode = this.options.preferredCountries[i].toLowerCase();
361
387
  var countryData = this._getCountryData(countryCode, false, true);
362
- if (countryData) this.preferredCountries.push(countryData);
388
+ if (countryData) {
389
+ this.preferredCountries.push(countryData);
390
+ }
363
391
  }
364
392
  }
365
393
  }, {
366
394
  key: "_createEl",
367
395
  value: function _createEl(name, attrs, container) {
368
396
  var el = document.createElement(name);
369
- if (attrs) forEachProp(attrs, function(key, value) {
370
- return el.setAttribute(key, value);
371
- });
372
- if (container) container.appendChild(el);
397
+ if (attrs) {
398
+ forEachProp(attrs, function(key, value) {
399
+ return el.setAttribute(key, value);
400
+ });
401
+ }
402
+ if (container) {
403
+ container.appendChild(el);
404
+ }
373
405
  return el;
374
406
  }
375
407
  }, {
@@ -378,51 +410,66 @@
378
410
  // if autocomplete does not exist on the element and its form, then
379
411
  // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can
380
412
  // easily put the plugin in an inconsistent state e.g. the wrong flag selected for the
381
- // autocompleted number, which on submit could mean wrong number is saved (esp in nationalMode)
413
+ // autocompleted number, which on submit could mean wrong number is saved
382
414
  if (!this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete"))) {
383
415
  this.telInput.setAttribute("autocomplete", "off");
384
416
  }
417
+ var _this$options = this.options, allowDropdown = _this$options.allowDropdown, separateDialCode = _this$options.separateDialCode, showFlags = _this$options.showFlags, customContainer = _this$options.customContainer, hiddenInput = _this$options.hiddenInput, dropdownContainer = _this$options.dropdownContainer;
385
418
  // containers (mostly for positioning)
386
419
  var parentClass = "iti";
387
- if (this.options.allowDropdown) parentClass += " iti--allow-dropdown";
388
- if (this.options.separateDialCode) parentClass += " iti--separate-dial-code";
389
- if (this.options.customContainer) {
390
- parentClass += " ";
391
- parentClass += this.options.customContainer;
420
+ if (allowDropdown) {
421
+ parentClass += " iti--allow-dropdown";
422
+ }
423
+ if (separateDialCode) {
424
+ parentClass += " iti--separate-dial-code";
425
+ }
426
+ if (showFlags) {
427
+ parentClass += " iti--show-flags";
428
+ }
429
+ if (customContainer) {
430
+ parentClass += " ".concat(customContainer);
392
431
  }
393
432
  var wrapper = this._createEl("div", {
394
433
  "class": parentClass
395
434
  });
396
435
  this.telInput.parentNode.insertBefore(wrapper, this.telInput);
397
- this.flagsContainer = this._createEl("div", {
398
- "class": "iti__flag-container"
399
- }, wrapper);
436
+ // only hide the flagsContainer if allowDropdown, showFlags and separateDialCode are all false
437
+ var showFlagsContainer = allowDropdown || showFlags || separateDialCode;
438
+ if (showFlagsContainer) {
439
+ this.flagsContainer = this._createEl("div", {
440
+ "class": "iti__flag-container"
441
+ }, wrapper);
442
+ }
400
443
  wrapper.appendChild(this.telInput);
401
444
  // selected flag (displayed to left of input)
402
445
  // using Aria tags for "Select-Only Combobox Example"
403
446
  // https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/
404
- this.selectedFlag = this._createEl("div", _objectSpread({
405
- "class": "iti__selected-flag"
406
- }, this.options.allowDropdown && {
407
- role: "combobox",
408
- "aria-haspopup": "listbox",
409
- "aria-controls": "iti-".concat(this.id, "__country-listbox"),
410
- "aria-owns": "iti-".concat(this.id, "__country-listbox"),
411
- "aria-expanded": "false",
412
- "aria-label": "Telephone country code"
413
- }), this.flagsContainer);
414
- this.selectedFlagInner = this._createEl("div", {
415
- "class": "iti__flag"
416
- }, this.selectedFlag);
417
- if (this.telInput.disabled) {
447
+ if (showFlagsContainer) {
448
+ this.selectedFlag = this._createEl("div", _objectSpread({
449
+ "class": "iti__selected-flag"
450
+ }, allowDropdown && {
451
+ role: "combobox",
452
+ "aria-haspopup": "listbox",
453
+ "aria-controls": "iti-".concat(this.id, "__country-listbox"),
454
+ "aria-owns": "iti-".concat(this.id, "__country-listbox"),
455
+ "aria-expanded": "false",
456
+ "aria-label": "Telephone country code"
457
+ }), this.flagsContainer);
458
+ }
459
+ if (showFlags) {
460
+ this.selectedFlagInner = this._createEl("div", {
461
+ "class": "iti__flag"
462
+ }, this.selectedFlag);
463
+ }
464
+ if (this.selectedFlag && this.telInput.disabled) {
418
465
  this.selectedFlag.setAttribute("aria-disabled", "true");
419
466
  }
420
- if (this.options.separateDialCode) {
467
+ if (separateDialCode) {
421
468
  this.selectedDialCode = this._createEl("div", {
422
469
  "class": "iti__selected-dial-code"
423
470
  }, this.selectedFlag);
424
471
  }
425
- if (this.options.allowDropdown) {
472
+ if (allowDropdown) {
426
473
  if (!this.telInput.disabled) {
427
474
  // make element focusable and tab navigable
428
475
  this.selectedFlag.setAttribute("tabindex", "0");
@@ -447,7 +494,7 @@
447
494
  }
448
495
  this._appendListItems(this.countries, "iti__standard");
449
496
  // create dropdownContainer markup
450
- if (this.options.dropdownContainer) {
497
+ if (dropdownContainer) {
451
498
  this.dropdown = this._createEl("div", {
452
499
  "class": "iti iti--container"
453
500
  });
@@ -456,14 +503,16 @@
456
503
  this.flagsContainer.appendChild(this.countryList);
457
504
  }
458
505
  }
459
- if (this.options.hiddenInput) {
460
- var hiddenInputName = this.options.hiddenInput;
506
+ if (hiddenInput) {
507
+ var hiddenInputName = hiddenInput;
461
508
  var name = this.telInput.getAttribute("name");
462
509
  if (name) {
463
510
  var i = name.lastIndexOf("[");
464
511
  // if input name contains square brackets, then give the hidden input the same name,
465
512
  // replacing the contents of the last set of brackets with the given hiddenInput name
466
- if (i !== -1) hiddenInputName = "".concat(name.substr(0, i), "[").concat(hiddenInputName, "]");
513
+ if (i !== -1) {
514
+ hiddenInputName = "".concat(name.substr(0, i), "[").concat(hiddenInputName, "]");
515
+ }
467
516
  }
468
517
  this.hiddenInput = this._createEl("input", {
469
518
  type: "hidden",
@@ -485,7 +534,9 @@
485
534
  // open the list item
486
535
  tmp += "<li class='iti__country ".concat(className, "' tabIndex='-1' id='iti-").concat(this.id, "__item-").concat(c.iso2).concat(idSuffix, "' role='option' data-dial-code='").concat(c.dialCode, "' data-country-code='").concat(c.iso2, "' aria-selected='false'>");
487
536
  // add the flag
488
- tmp += "<div class='iti__flag-box'><div class='iti__flag iti__".concat(c.iso2, "'></div></div>");
537
+ if (this.options.showFlags) {
538
+ tmp += "<div class='iti__flag-box'><div class='iti__flag iti__".concat(c.iso2, "'></div></div>");
539
+ }
489
540
  // and the country name and dial code
490
541
  tmp += "<span class='iti__country-name'>".concat(c.name, "</span>");
491
542
  tmp += "<span class='iti__dial-code'>+".concat(c.dialCode, "</span>");
@@ -506,7 +557,7 @@
506
557
  var val = useAttribute ? attributeValue : inputValue;
507
558
  var dialCode = this._getDialCode(val);
508
559
  var isRegionlessNanp = this._isRegionlessNanp(val);
509
- var _this$options = this.options, initialCountry = _this$options.initialCountry, autoInsertDialCode = _this$options.autoInsertDialCode;
560
+ var _this$options2 = this.options, initialCountry = _this$options2.initialCountry, autoInsertDialCode = _this$options2.autoInsertDialCode;
510
561
  // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the
511
562
  // flag, else fall back to the default country
512
563
  if (dialCode && !isRegionlessNanp) {
@@ -534,15 +585,23 @@
534
585
  }
535
586
  // NOTE: if initialCountry is set to auto, that will be handled separately
536
587
  // format - note this wont be run after _updateDialCode as that's only called if no val
537
- if (val) this._updateValFromNumber(val);
588
+ if (val) {
589
+ this._updateValFromNumber(val);
590
+ }
538
591
  }
539
592
  }, {
540
593
  key: "_initListeners",
541
594
  value: function _initListeners() {
542
595
  this._initKeyListeners();
543
- if (this.options.autoInsertDialCode) this._initBlurListeners();
544
- if (this.options.allowDropdown) this._initDropdownListeners();
545
- if (this.hiddenInput) this._initHiddenInputListener();
596
+ if (this.options.autoInsertDialCode) {
597
+ this._initBlurListeners();
598
+ }
599
+ if (this.options.allowDropdown) {
600
+ this._initDropdownListeners();
601
+ }
602
+ if (this.hiddenInput) {
603
+ this._initHiddenInputListener();
604
+ }
546
605
  }
547
606
  }, {
548
607
  key: "_initHiddenInputListener",
@@ -551,7 +610,9 @@
551
610
  this._handleHiddenInputSubmit = function() {
552
611
  _this3.hiddenInput.value = _this3.getNumber();
553
612
  };
554
- if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit);
613
+ if (this.telInput.form) {
614
+ this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit);
615
+ }
555
616
  }
556
617
  }, {
557
618
  key: "_getClosestLabel",
@@ -571,10 +632,16 @@
571
632
  // close it again
572
633
  this._handleLabelClick = function(e) {
573
634
  // if the dropdown is closed, then focus the input, else ignore the click
574
- if (_this4.countryList.classList.contains("iti__hide")) _this4.telInput.focus(); else e.preventDefault();
635
+ if (_this4.countryList.classList.contains("iti__hide")) {
636
+ _this4.telInput.focus();
637
+ } else {
638
+ e.preventDefault();
639
+ }
575
640
  };
576
641
  var label = this._getClosestLabel();
577
- if (label) label.addEventListener("click", this._handleLabelClick);
642
+ if (label) {
643
+ label.addEventListener("click", this._handleLabelClick);
644
+ }
578
645
  // toggle country dropdown on click
579
646
  this._handleClickSelectedFlag = function() {
580
647
  // only intercept this event if we're opening the dropdown
@@ -596,7 +663,9 @@
596
663
  _this4._showDropdown();
597
664
  }
598
665
  // allow navigation from dropdown to input on TAB
599
- if (e.key === "Tab") _this4._closeDropdown();
666
+ if (e.key === "Tab") {
667
+ _this4._closeDropdown();
668
+ }
600
669
  };
601
670
  this.flagsContainer.addEventListener("keydown", this._handleFlagsContainerKeydown);
602
671
  }
@@ -615,8 +684,14 @@
615
684
  window.intlTelInputGlobals.loadUtils(_this5.options.utilsScript);
616
685
  });
617
686
  }
618
- } else this.resolveUtilsScriptPromise();
619
- if (this.options.initialCountry === "auto") this._loadAutoCountry(); else this.resolveAutoCountryPromise();
687
+ } else {
688
+ this.resolveUtilsScriptPromise();
689
+ }
690
+ if (this.options.initialCountry === "auto") {
691
+ this._loadAutoCountry();
692
+ } else {
693
+ this.resolveAutoCountryPromise();
694
+ }
620
695
  }
621
696
  }, {
622
697
  key: "_loadAutoCountry",
@@ -681,7 +756,9 @@
681
756
  this._handleSubmitOrBlurEvent = function() {
682
757
  _this7._removeEmptyDialCode();
683
758
  };
684
- if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleSubmitOrBlurEvent);
759
+ if (this.telInput.form) {
760
+ this.telInput.form.addEventListener("submit", this._handleSubmitOrBlurEvent);
761
+ }
685
762
  this.telInput.addEventListener("blur", this._handleSubmitOrBlurEvent);
686
763
  }
687
764
  }, {
@@ -729,7 +806,11 @@
729
806
  }, {
730
807
  key: "_toggleClass",
731
808
  value: function _toggleClass(el, className, shouldHaveClass) {
732
- if (shouldHaveClass && !el.classList.contains(className)) el.classList.add(className); else if (!shouldHaveClass && el.classList.contains(className)) el.classList.remove(className);
809
+ if (shouldHaveClass && !el.classList.contains(className)) {
810
+ el.classList.add(className);
811
+ } else if (!shouldHaveClass && el.classList.contains(className)) {
812
+ el.classList.remove(className);
813
+ }
733
814
  }
734
815
  }, {
735
816
  key: "_setDropdownPosition",
@@ -785,13 +866,17 @@
785
866
  this._handleMouseoverCountryList = function(e) {
786
867
  // handle event delegation, as we're listening for this event on the countryList
787
868
  var listItem = _this9._getClosestListItem(e.target);
788
- if (listItem) _this9._highlightListItem(listItem, false);
869
+ if (listItem) {
870
+ _this9._highlightListItem(listItem, false);
871
+ }
789
872
  };
790
873
  this.countryList.addEventListener("mouseover", this._handleMouseoverCountryList);
791
874
  // listen for country selection
792
875
  this._handleClickCountryList = function(e) {
793
876
  var listItem = _this9._getClosestListItem(e.target);
794
- if (listItem) _this9._selectListItem(listItem);
877
+ if (listItem) {
878
+ _this9._selectListItem(listItem);
879
+ }
795
880
  };
796
881
  this.countryList.addEventListener("click", this._handleClickCountryList);
797
882
  // click off to close
@@ -799,7 +884,9 @@
799
884
  // we cannot just stopPropagation as it may be needed to close another instance
800
885
  var isOpening = true;
801
886
  this._handleClickOffToClose = function() {
802
- if (!isOpening) _this9._closeDropdown();
887
+ if (!isOpening) {
888
+ _this9._closeDropdown();
889
+ }
803
890
  isOpening = false;
804
891
  };
805
892
  document.documentElement.addEventListener("click", this._handleClickOffToClose);
@@ -814,9 +901,17 @@
814
901
  // and enter key from submitting a form etc
815
902
  e.preventDefault();
816
903
  // up and down to navigate
817
- if (e.key === "ArrowUp" || e.key === "Up" || e.key === "ArrowDown" || e.key === "Down") _this9._handleUpDownKey(e.key); else if (e.key === "Enter") _this9._handleEnterKey(); else if (e.key === "Escape") _this9._closeDropdown(); else if (/^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(e.key)) {
904
+ if (e.key === "ArrowUp" || e.key === "Up" || e.key === "ArrowDown" || e.key === "Down") {
905
+ _this9._handleUpDownKey(e.key);
906
+ } else if (e.key === "Enter") {
907
+ _this9._handleEnterKey();
908
+ } else if (e.key === "Escape") {
909
+ _this9._closeDropdown();
910
+ } else if (/^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(e.key)) {
818
911
  // jump to countries that start with the query string
819
- if (queryTimer) clearTimeout(queryTimer);
912
+ if (queryTimer) {
913
+ clearTimeout(queryTimer);
914
+ }
820
915
  query += e.key.toLowerCase();
821
916
  _this9._searchForCountry(query);
822
917
  // if the timer hits 1 second, reset the query
@@ -842,7 +937,9 @@
842
937
  }, {
843
938
  key: "_handleEnterKey",
844
939
  value: function _handleEnterKey() {
845
- if (this.highlightedItem) this._selectListItem(this.highlightedItem);
940
+ if (this.highlightedItem) {
941
+ this._selectListItem(this.highlightedItem);
942
+ }
846
943
  }
847
944
  }, {
848
945
  key: "_searchForCountry",
@@ -878,7 +975,7 @@
878
975
  }, {
879
976
  key: "_updateFlagFromNumber",
880
977
  value: function _updateFlagFromNumber(originalNumber) {
881
- // if we're in nationalMode and we already have US/Canada selected, make sure the number starts
978
+ // if we already have US/Canada selected, make sure the number starts
882
979
  // with a +1 so _getDialCode will be able to extract the area code
883
980
  // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag
884
981
  // from the number), that means we're initialising the plugin with a number that already has a
@@ -886,8 +983,10 @@
886
983
  var number = originalNumber;
887
984
  var selectedDialCode = this.selectedCountryData.dialCode;
888
985
  var isNanp = selectedDialCode === "1";
889
- if (number && this.options.nationalMode && isNanp && number.charAt(0) !== "+") {
890
- if (number.charAt(0) !== "1") number = "1".concat(number);
986
+ if (number && isNanp && number.charAt(0) !== "+") {
987
+ if (number.charAt(0) !== "1") {
988
+ number = "1".concat(number);
989
+ }
891
990
  number = "+".concat(number);
892
991
  }
893
992
  // if separateDialCode enabled, then consider the selected dial code to be part of the number
@@ -948,11 +1047,15 @@
948
1047
  key: "_highlightListItem",
949
1048
  value: function _highlightListItem(listItem, shouldFocus) {
950
1049
  var prevItem = this.highlightedItem;
951
- if (prevItem) prevItem.classList.remove("iti__highlight");
1050
+ if (prevItem) {
1051
+ prevItem.classList.remove("iti__highlight");
1052
+ }
952
1053
  this.highlightedItem = listItem;
953
1054
  this.highlightedItem.classList.add("iti__highlight");
954
1055
  this.selectedFlag.setAttribute("aria-activedescendant", listItem.getAttribute("id"));
955
- if (shouldFocus) this.highlightedItem.focus();
1056
+ if (shouldFocus) {
1057
+ this.highlightedItem.focus();
1058
+ }
956
1059
  }
957
1060
  }, {
958
1061
  key: "_getCountryData",
@@ -978,10 +1081,14 @@
978
1081
  if (this.selectedCountryData.iso2) {
979
1082
  this.defaultCountry = this.selectedCountryData.iso2;
980
1083
  }
981
- this.selectedFlagInner.setAttribute("class", "iti__flag iti__".concat(countryCode));
1084
+ if (this.options.showFlags) {
1085
+ this.selectedFlagInner.setAttribute("class", "iti__flag iti__".concat(countryCode));
1086
+ }
982
1087
  // update the selected country's title attribute
983
- var title = countryCode ? "".concat(this.selectedCountryData.name, ": +").concat(this.selectedCountryData.dialCode) : "Unknown";
984
- this.selectedFlag.setAttribute("title", title);
1088
+ if (this.selectedFlag) {
1089
+ var title = countryCode ? "".concat(this.selectedCountryData.name, ": +").concat(this.selectedCountryData.dialCode) : "Unknown";
1090
+ this.selectedFlag.setAttribute("title", title);
1091
+ }
985
1092
  if (this.options.separateDialCode) {
986
1093
  var dialCode = this.selectedCountryData.dialCode ? "+".concat(this.selectedCountryData.dialCode) : "";
987
1094
  this.selectedDialCode.innerHTML = dialCode;
@@ -1049,8 +1156,8 @@
1049
1156
  this._updateDialCode(listItem.getAttribute("data-dial-code"));
1050
1157
  // focus the input
1051
1158
  this.telInput.focus();
1052
- // put cursor at end - this fix is required for FF and IE11 (with nationalMode=false i.e. auto
1053
- // inserting dial code), who try to put the cursor at the beginning the first time
1159
+ // put cursor at end - this fix is required for FF and IE11 (with auto inserting dial code),
1160
+ // who try to put the cursor at the beginning the first time
1054
1161
  var len = this.telInput.value.length;
1055
1162
  this.telInput.setSelectionRange(len, len);
1056
1163
  if (flagChanged) {
@@ -1072,8 +1179,12 @@
1072
1179
  this.countryList.removeEventListener("click", this._handleClickCountryList);
1073
1180
  // remove menu from container
1074
1181
  if (this.options.dropdownContainer) {
1075
- if (!this.isMobile) window.removeEventListener("scroll", this._handleWindowScroll);
1076
- if (this.dropdown.parentNode) this.dropdown.parentNode.removeChild(this.dropdown);
1182
+ if (!this.isMobile) {
1183
+ window.removeEventListener("scroll", this._handleWindowScroll);
1184
+ }
1185
+ if (this.dropdown.parentNode) {
1186
+ this.dropdown.parentNode.removeChild(this.dropdown);
1187
+ }
1077
1188
  }
1078
1189
  this._trigger("close:countrydropdown");
1079
1190
  }
@@ -1093,11 +1204,15 @@
1093
1204
  var middleOffset = containerHeight / 2 - elementHeight / 2;
1094
1205
  if (elementTop < containerTop) {
1095
1206
  // scroll up
1096
- if (middle) newScrollTop -= middleOffset;
1207
+ if (middle) {
1208
+ newScrollTop -= middleOffset;
1209
+ }
1097
1210
  container.scrollTop = newScrollTop;
1098
1211
  } else if (elementBottom > containerBottom) {
1099
1212
  // scroll down
1100
- if (middle) newScrollTop += middleOffset;
1213
+ if (middle) {
1214
+ newScrollTop += middleOffset;
1215
+ }
1101
1216
  var heightDifference = containerHeight - elementHeight;
1102
1217
  container.scrollTop = newScrollTop - heightDifference;
1103
1218
  }
@@ -1110,7 +1225,7 @@
1110
1225
  var newDialCode = "+".concat(newDialCodeBare);
1111
1226
  var newNumber;
1112
1227
  if (inputVal.charAt(0) === "+") {
1113
- // there's a plus so we're dealing with a replacement (doesn't matter if nationalMode or not)
1228
+ // there's a plus so we're dealing with a replacement
1114
1229
  var prevDialCode = this._getDialCode(inputVal);
1115
1230
  if (prevDialCode) {
1116
1231
  // current number contains a valid dial code, so replace it
@@ -1244,13 +1359,19 @@
1244
1359
  this.flagsContainer.removeEventListener("keydown", this._handleFlagsContainerKeydown);
1245
1360
  // label click hack
1246
1361
  var label = this._getClosestLabel();
1247
- if (label) label.removeEventListener("click", this._handleLabelClick);
1362
+ if (label) {
1363
+ label.removeEventListener("click", this._handleLabelClick);
1364
+ }
1248
1365
  }
1249
1366
  // unbind hiddenInput listeners
1250
- if (this.hiddenInput && form) form.removeEventListener("submit", this._handleHiddenInputSubmit);
1367
+ if (this.hiddenInput && form) {
1368
+ form.removeEventListener("submit", this._handleHiddenInputSubmit);
1369
+ }
1251
1370
  // unbind autoInsertDialCode listeners
1252
1371
  if (this.options.autoInsertDialCode) {
1253
- if (form) form.removeEventListener("submit", this._handleSubmitOrBlurEvent);
1372
+ if (form) {
1373
+ form.removeEventListener("submit", this._handleSubmitOrBlurEvent);
1374
+ }
1254
1375
  this.telInput.removeEventListener("blur", this._handleSubmitOrBlurEvent);
1255
1376
  }
1256
1377
  // unbind key events, and cut/paste events
@@ -1308,15 +1429,14 @@
1308
1429
  key: "isValidNumber",
1309
1430
  value: function isValidNumber() {
1310
1431
  var val = this._getFullNumber().trim();
1311
- var countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : "";
1312
- return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null;
1432
+ return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, this.selectedCountryData.iso2) : null;
1313
1433
  }
1314
1434
  }, {
1315
1435
  key: "setCountry",
1316
1436
  value: function setCountry(originalCountryCode) {
1317
1437
  var countryCode = originalCountryCode.toLowerCase();
1318
1438
  // check if already selected
1319
- if (!this.selectedFlagInner.classList.contains("iti__".concat(countryCode))) {
1439
+ if (this.selectedCountryData.iso2 !== countryCode) {
1320
1440
  this._setFlag(countryCode);
1321
1441
  this._updateDialCode(this.selectedCountryData.dialCode);
1322
1442
  this._triggerCountryChange();
@@ -1355,11 +1475,15 @@
1355
1475
  var script = document.createElement("script");
1356
1476
  script.onload = function() {
1357
1477
  forEachInstance("handleUtils");
1358
- if (handleSuccess) handleSuccess();
1478
+ if (handleSuccess) {
1479
+ handleSuccess();
1480
+ }
1359
1481
  };
1360
1482
  script.onerror = function() {
1361
1483
  forEachInstance("rejectUtilsScriptPromise");
1362
- if (handleFailure) handleFailure();
1484
+ if (handleFailure) {
1485
+ handleFailure();
1486
+ }
1363
1487
  };
1364
1488
  script.className = "iti-load-utils";
1365
1489
  script.async = true;
@@ -1388,7 +1512,7 @@
1388
1512
  // default options
1389
1513
  intlTelInputGlobals.defaults = defaults;
1390
1514
  // version
1391
- intlTelInputGlobals.version = "18.0.3";
1515
+ intlTelInputGlobals.version = "18.1.1";
1392
1516
  // convenience wrapper
1393
1517
  return function(input, options) {
1394
1518
  var iti = new Iti(input, options);