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
  */
@@ -118,7 +118,9 @@
118
118
  return document.readyState === "complete";
119
119
  }
120
120
  };
121
- if (typeof window === "object") window.intlTelInputGlobals = intlTelInputGlobals;
121
+ if (typeof window === "object") {
122
+ window.intlTelInputGlobals = intlTelInputGlobals;
123
+ }
122
124
  // these vars persist through all instances of the plugin
123
125
  var id = 0;
124
126
  var defaults = {
@@ -147,7 +149,7 @@
147
149
  initialCountry: "",
148
150
  // localized country names e.g. { 'de': 'Deutschland' }
149
151
  localizedCountries: null,
150
- // deal with national numbers instead of international numbers
152
+ // national vs international formatting for numbers e.g. placeholders and displaying existing numbers
151
153
  nationalMode: true,
152
154
  // display only these countries
153
155
  onlyCountries: [],
@@ -157,6 +159,8 @@
157
159
  preferredCountries: [ "us", "gb" ],
158
160
  // display the country dial code next to the selected flag
159
161
  separateDialCode: false,
162
+ // option to hide the flags - must be used with separateDialCode, or allowDropdown=false
163
+ showFlags: true,
160
164
  // specify the path to the libphonenumber script to enable validation/formatting
161
165
  utilsScript: ""
162
166
  };
@@ -200,9 +204,19 @@
200
204
  value: function _init() {
201
205
  var _this2 = this;
202
206
  // if in nationalMode, do not insert dial codes
203
- if (this.options.nationalMode) this.options.autoInsertDialCode = false;
207
+ if (this.options.nationalMode) {
208
+ this.options.autoInsertDialCode = false;
209
+ }
204
210
  // if separateDialCode enabled, do not insert dial codes
205
- if (this.options.separateDialCode) this.options.autoInsertDialCode = false;
211
+ if (this.options.separateDialCode) {
212
+ this.options.autoInsertDialCode = false;
213
+ }
214
+ // force showFlags=true if there's a dropdown and we're not displaying the dial code,
215
+ // as otherwise you just have a down arrow on it's own which doesn't make sense
216
+ var forceShowFlags = this.options.allowDropdown && !this.options.separateDialCode;
217
+ if (!this.options.showFlags && forceShowFlags) {
218
+ this.options.showFlags = true;
219
+ }
206
220
  // we cannot just test screen size as some smartphones/website meta tags will report desktop
207
221
  // resolutions
208
222
  // Note: for some reason jasmine breaks if you put this in the main Plugin function with the
@@ -213,7 +227,9 @@
213
227
  // trigger the mobile dropdown css
214
228
  document.body.classList.add("iti-mobile");
215
229
  // on mobile, we want a full screen dropdown, so we must append it to the body
216
- if (!this.options.dropdownContainer) this.options.dropdownContainer = document.body;
230
+ if (!this.options.dropdownContainer) {
231
+ this.options.dropdownContainer = document.body;
232
+ }
217
233
  }
218
234
  // these promises get resolved when their individual requests complete
219
235
  // this way the dev can do something like iti.promise.then(...) to know when all requests are
@@ -257,7 +273,9 @@
257
273
  // process the preferredCountries
258
274
  this._processPreferredCountries();
259
275
  // translate countries according to localizedCountries option
260
- if (this.options.localizedCountries) this._translateCountriesByLocale();
276
+ if (this.options.localizedCountries) {
277
+ this._translateCountriesByLocale();
278
+ }
261
279
  // sort countries by name
262
280
  if (this.options.onlyCountries.length || this.options.localizedCountries) {
263
281
  this.countries.sort(this._countryNameSort);
@@ -274,7 +292,9 @@
274
292
  }
275
293
  // bail if we already have this country for this countryCode
276
294
  for (var i = 0; i < this.countryCodes[countryCode].length; i++) {
277
- if (this.countryCodes[countryCode][i] === iso2) return;
295
+ if (this.countryCodes[countryCode][i] === iso2) {
296
+ return;
297
+ }
278
298
  }
279
299
  // check for undefined as 0 is falsy
280
300
  var index = priority !== undefined ? priority : this.countryCodes[countryCode].length;
@@ -314,8 +334,12 @@
314
334
  }, {
315
335
  key: "_countryNameSort",
316
336
  value: function _countryNameSort(a, b) {
317
- if (a.name < b.name) return -1;
318
- if (a.name > b.name) return 1;
337
+ if (a.name < b.name) {
338
+ return -1;
339
+ }
340
+ if (a.name > b.name) {
341
+ return 1;
342
+ }
319
343
  return 0;
320
344
  }
321
345
  }, {
@@ -329,7 +353,9 @@
329
353
  // first: add dial codes
330
354
  for (var i = 0; i < this.countries.length; i++) {
331
355
  var c = this.countries[i];
332
- if (!this.dialCodes[c.dialCode]) this.dialCodes[c.dialCode] = true;
356
+ if (!this.dialCodes[c.dialCode]) {
357
+ this.dialCodes[c.dialCode] = true;
358
+ }
333
359
  this._addCountryCode(c.iso2, c.dialCode, c.priority);
334
360
  }
335
361
  // next: add area codes
@@ -364,17 +390,23 @@
364
390
  for (var i = 0; i < this.options.preferredCountries.length; i++) {
365
391
  var countryCode = this.options.preferredCountries[i].toLowerCase();
366
392
  var countryData = this._getCountryData(countryCode, false, true);
367
- if (countryData) this.preferredCountries.push(countryData);
393
+ if (countryData) {
394
+ this.preferredCountries.push(countryData);
395
+ }
368
396
  }
369
397
  }
370
398
  }, {
371
399
  key: "_createEl",
372
400
  value: function _createEl(name, attrs, container) {
373
401
  var el = document.createElement(name);
374
- if (attrs) forEachProp(attrs, function(key, value) {
375
- return el.setAttribute(key, value);
376
- });
377
- if (container) container.appendChild(el);
402
+ if (attrs) {
403
+ forEachProp(attrs, function(key, value) {
404
+ return el.setAttribute(key, value);
405
+ });
406
+ }
407
+ if (container) {
408
+ container.appendChild(el);
409
+ }
378
410
  return el;
379
411
  }
380
412
  }, {
@@ -383,51 +415,66 @@
383
415
  // if autocomplete does not exist on the element and its form, then
384
416
  // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can
385
417
  // easily put the plugin in an inconsistent state e.g. the wrong flag selected for the
386
- // autocompleted number, which on submit could mean wrong number is saved (esp in nationalMode)
418
+ // autocompleted number, which on submit could mean wrong number is saved
387
419
  if (!this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete"))) {
388
420
  this.telInput.setAttribute("autocomplete", "off");
389
421
  }
422
+ 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;
390
423
  // containers (mostly for positioning)
391
424
  var parentClass = "iti";
392
- if (this.options.allowDropdown) parentClass += " iti--allow-dropdown";
393
- if (this.options.separateDialCode) parentClass += " iti--separate-dial-code";
394
- if (this.options.customContainer) {
395
- parentClass += " ";
396
- parentClass += this.options.customContainer;
425
+ if (allowDropdown) {
426
+ parentClass += " iti--allow-dropdown";
427
+ }
428
+ if (separateDialCode) {
429
+ parentClass += " iti--separate-dial-code";
430
+ }
431
+ if (showFlags) {
432
+ parentClass += " iti--show-flags";
433
+ }
434
+ if (customContainer) {
435
+ parentClass += " ".concat(customContainer);
397
436
  }
398
437
  var wrapper = this._createEl("div", {
399
438
  "class": parentClass
400
439
  });
401
440
  this.telInput.parentNode.insertBefore(wrapper, this.telInput);
402
- this.flagsContainer = this._createEl("div", {
403
- "class": "iti__flag-container"
404
- }, wrapper);
441
+ // only hide the flagsContainer if allowDropdown, showFlags and separateDialCode are all false
442
+ var showFlagsContainer = allowDropdown || showFlags || separateDialCode;
443
+ if (showFlagsContainer) {
444
+ this.flagsContainer = this._createEl("div", {
445
+ "class": "iti__flag-container"
446
+ }, wrapper);
447
+ }
405
448
  wrapper.appendChild(this.telInput);
406
449
  // selected flag (displayed to left of input)
407
450
  // using Aria tags for "Select-Only Combobox Example"
408
451
  // https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/
409
- this.selectedFlag = this._createEl("div", _objectSpread({
410
- "class": "iti__selected-flag"
411
- }, this.options.allowDropdown && {
412
- role: "combobox",
413
- "aria-haspopup": "listbox",
414
- "aria-controls": "iti-".concat(this.id, "__country-listbox"),
415
- "aria-owns": "iti-".concat(this.id, "__country-listbox"),
416
- "aria-expanded": "false",
417
- "aria-label": "Telephone country code"
418
- }), this.flagsContainer);
419
- this.selectedFlagInner = this._createEl("div", {
420
- "class": "iti__flag"
421
- }, this.selectedFlag);
422
- if (this.telInput.disabled) {
452
+ if (showFlagsContainer) {
453
+ this.selectedFlag = this._createEl("div", _objectSpread({
454
+ "class": "iti__selected-flag"
455
+ }, allowDropdown && {
456
+ role: "combobox",
457
+ "aria-haspopup": "listbox",
458
+ "aria-controls": "iti-".concat(this.id, "__country-listbox"),
459
+ "aria-owns": "iti-".concat(this.id, "__country-listbox"),
460
+ "aria-expanded": "false",
461
+ "aria-label": "Telephone country code"
462
+ }), this.flagsContainer);
463
+ }
464
+ if (showFlags) {
465
+ this.selectedFlagInner = this._createEl("div", {
466
+ "class": "iti__flag"
467
+ }, this.selectedFlag);
468
+ }
469
+ if (this.selectedFlag && this.telInput.disabled) {
423
470
  this.selectedFlag.setAttribute("aria-disabled", "true");
424
471
  }
425
- if (this.options.separateDialCode) {
472
+ if (separateDialCode) {
426
473
  this.selectedDialCode = this._createEl("div", {
427
474
  "class": "iti__selected-dial-code"
428
475
  }, this.selectedFlag);
429
476
  }
430
- if (this.options.allowDropdown) {
477
+ if (allowDropdown) {
431
478
  if (!this.telInput.disabled) {
432
479
  // make element focusable and tab navigable
433
480
  this.selectedFlag.setAttribute("tabindex", "0");
@@ -452,7 +499,7 @@
452
499
  }
453
500
  this._appendListItems(this.countries, "iti__standard");
454
501
  // create dropdownContainer markup
455
- if (this.options.dropdownContainer) {
502
+ if (dropdownContainer) {
456
503
  this.dropdown = this._createEl("div", {
457
504
  "class": "iti iti--container"
458
505
  });
@@ -461,14 +508,16 @@
461
508
  this.flagsContainer.appendChild(this.countryList);
462
509
  }
463
510
  }
464
- if (this.options.hiddenInput) {
465
- var hiddenInputName = this.options.hiddenInput;
511
+ if (hiddenInput) {
512
+ var hiddenInputName = hiddenInput;
466
513
  var name = this.telInput.getAttribute("name");
467
514
  if (name) {
468
515
  var i = name.lastIndexOf("[");
469
516
  // if input name contains square brackets, then give the hidden input the same name,
470
517
  // replacing the contents of the last set of brackets with the given hiddenInput name
471
- if (i !== -1) hiddenInputName = "".concat(name.substr(0, i), "[").concat(hiddenInputName, "]");
518
+ if (i !== -1) {
519
+ hiddenInputName = "".concat(name.substr(0, i), "[").concat(hiddenInputName, "]");
520
+ }
472
521
  }
473
522
  this.hiddenInput = this._createEl("input", {
474
523
  type: "hidden",
@@ -490,7 +539,9 @@
490
539
  // open the list item
491
540
  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'>");
492
541
  // add the flag
493
- tmp += "<div class='iti__flag-box'><div class='iti__flag iti__".concat(c.iso2, "'></div></div>");
542
+ if (this.options.showFlags) {
543
+ tmp += "<div class='iti__flag-box'><div class='iti__flag iti__".concat(c.iso2, "'></div></div>");
544
+ }
494
545
  // and the country name and dial code
495
546
  tmp += "<span class='iti__country-name'>".concat(c.name, "</span>");
496
547
  tmp += "<span class='iti__dial-code'>+".concat(c.dialCode, "</span>");
@@ -511,7 +562,7 @@
511
562
  var val = useAttribute ? attributeValue : inputValue;
512
563
  var dialCode = this._getDialCode(val);
513
564
  var isRegionlessNanp = this._isRegionlessNanp(val);
514
- var _this$options = this.options, initialCountry = _this$options.initialCountry, autoInsertDialCode = _this$options.autoInsertDialCode;
565
+ var _this$options2 = this.options, initialCountry = _this$options2.initialCountry, autoInsertDialCode = _this$options2.autoInsertDialCode;
515
566
  // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the
516
567
  // flag, else fall back to the default country
517
568
  if (dialCode && !isRegionlessNanp) {
@@ -539,15 +590,23 @@
539
590
  }
540
591
  // NOTE: if initialCountry is set to auto, that will be handled separately
541
592
  // format - note this wont be run after _updateDialCode as that's only called if no val
542
- if (val) this._updateValFromNumber(val);
593
+ if (val) {
594
+ this._updateValFromNumber(val);
595
+ }
543
596
  }
544
597
  }, {
545
598
  key: "_initListeners",
546
599
  value: function _initListeners() {
547
600
  this._initKeyListeners();
548
- if (this.options.autoInsertDialCode) this._initBlurListeners();
549
- if (this.options.allowDropdown) this._initDropdownListeners();
550
- if (this.hiddenInput) this._initHiddenInputListener();
601
+ if (this.options.autoInsertDialCode) {
602
+ this._initBlurListeners();
603
+ }
604
+ if (this.options.allowDropdown) {
605
+ this._initDropdownListeners();
606
+ }
607
+ if (this.hiddenInput) {
608
+ this._initHiddenInputListener();
609
+ }
551
610
  }
552
611
  }, {
553
612
  key: "_initHiddenInputListener",
@@ -556,7 +615,9 @@
556
615
  this._handleHiddenInputSubmit = function() {
557
616
  _this3.hiddenInput.value = _this3.getNumber();
558
617
  };
559
- if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit);
618
+ if (this.telInput.form) {
619
+ this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit);
620
+ }
560
621
  }
561
622
  }, {
562
623
  key: "_getClosestLabel",
@@ -576,10 +637,16 @@
576
637
  // close it again
577
638
  this._handleLabelClick = function(e) {
578
639
  // if the dropdown is closed, then focus the input, else ignore the click
579
- if (_this4.countryList.classList.contains("iti__hide")) _this4.telInput.focus(); else e.preventDefault();
640
+ if (_this4.countryList.classList.contains("iti__hide")) {
641
+ _this4.telInput.focus();
642
+ } else {
643
+ e.preventDefault();
644
+ }
580
645
  };
581
646
  var label = this._getClosestLabel();
582
- if (label) label.addEventListener("click", this._handleLabelClick);
647
+ if (label) {
648
+ label.addEventListener("click", this._handleLabelClick);
649
+ }
583
650
  // toggle country dropdown on click
584
651
  this._handleClickSelectedFlag = function() {
585
652
  // only intercept this event if we're opening the dropdown
@@ -601,7 +668,9 @@
601
668
  _this4._showDropdown();
602
669
  }
603
670
  // allow navigation from dropdown to input on TAB
604
- if (e.key === "Tab") _this4._closeDropdown();
671
+ if (e.key === "Tab") {
672
+ _this4._closeDropdown();
673
+ }
605
674
  };
606
675
  this.flagsContainer.addEventListener("keydown", this._handleFlagsContainerKeydown);
607
676
  }
@@ -620,8 +689,14 @@
620
689
  window.intlTelInputGlobals.loadUtils(_this5.options.utilsScript);
621
690
  });
622
691
  }
623
- } else this.resolveUtilsScriptPromise();
624
- if (this.options.initialCountry === "auto") this._loadAutoCountry(); else this.resolveAutoCountryPromise();
692
+ } else {
693
+ this.resolveUtilsScriptPromise();
694
+ }
695
+ if (this.options.initialCountry === "auto") {
696
+ this._loadAutoCountry();
697
+ } else {
698
+ this.resolveAutoCountryPromise();
699
+ }
625
700
  }
626
701
  }, {
627
702
  key: "_loadAutoCountry",
@@ -686,7 +761,9 @@
686
761
  this._handleSubmitOrBlurEvent = function() {
687
762
  _this7._removeEmptyDialCode();
688
763
  };
689
- if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleSubmitOrBlurEvent);
764
+ if (this.telInput.form) {
765
+ this.telInput.form.addEventListener("submit", this._handleSubmitOrBlurEvent);
766
+ }
690
767
  this.telInput.addEventListener("blur", this._handleSubmitOrBlurEvent);
691
768
  }
692
769
  }, {
@@ -734,7 +811,11 @@
734
811
  }, {
735
812
  key: "_toggleClass",
736
813
  value: function _toggleClass(el, className, shouldHaveClass) {
737
- if (shouldHaveClass && !el.classList.contains(className)) el.classList.add(className); else if (!shouldHaveClass && el.classList.contains(className)) el.classList.remove(className);
814
+ if (shouldHaveClass && !el.classList.contains(className)) {
815
+ el.classList.add(className);
816
+ } else if (!shouldHaveClass && el.classList.contains(className)) {
817
+ el.classList.remove(className);
818
+ }
738
819
  }
739
820
  }, {
740
821
  key: "_setDropdownPosition",
@@ -790,13 +871,17 @@
790
871
  this._handleMouseoverCountryList = function(e) {
791
872
  // handle event delegation, as we're listening for this event on the countryList
792
873
  var listItem = _this9._getClosestListItem(e.target);
793
- if (listItem) _this9._highlightListItem(listItem, false);
874
+ if (listItem) {
875
+ _this9._highlightListItem(listItem, false);
876
+ }
794
877
  };
795
878
  this.countryList.addEventListener("mouseover", this._handleMouseoverCountryList);
796
879
  // listen for country selection
797
880
  this._handleClickCountryList = function(e) {
798
881
  var listItem = _this9._getClosestListItem(e.target);
799
- if (listItem) _this9._selectListItem(listItem);
882
+ if (listItem) {
883
+ _this9._selectListItem(listItem);
884
+ }
800
885
  };
801
886
  this.countryList.addEventListener("click", this._handleClickCountryList);
802
887
  // click off to close
@@ -804,7 +889,9 @@
804
889
  // we cannot just stopPropagation as it may be needed to close another instance
805
890
  var isOpening = true;
806
891
  this._handleClickOffToClose = function() {
807
- if (!isOpening) _this9._closeDropdown();
892
+ if (!isOpening) {
893
+ _this9._closeDropdown();
894
+ }
808
895
  isOpening = false;
809
896
  };
810
897
  document.documentElement.addEventListener("click", this._handleClickOffToClose);
@@ -819,9 +906,17 @@
819
906
  // and enter key from submitting a form etc
820
907
  e.preventDefault();
821
908
  // up and down to navigate
822
- 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)) {
909
+ if (e.key === "ArrowUp" || e.key === "Up" || e.key === "ArrowDown" || e.key === "Down") {
910
+ _this9._handleUpDownKey(e.key);
911
+ } else if (e.key === "Enter") {
912
+ _this9._handleEnterKey();
913
+ } else if (e.key === "Escape") {
914
+ _this9._closeDropdown();
915
+ } else if (/^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(e.key)) {
823
916
  // jump to countries that start with the query string
824
- if (queryTimer) clearTimeout(queryTimer);
917
+ if (queryTimer) {
918
+ clearTimeout(queryTimer);
919
+ }
825
920
  query += e.key.toLowerCase();
826
921
  _this9._searchForCountry(query);
827
922
  // if the timer hits 1 second, reset the query
@@ -847,7 +942,9 @@
847
942
  }, {
848
943
  key: "_handleEnterKey",
849
944
  value: function _handleEnterKey() {
850
- if (this.highlightedItem) this._selectListItem(this.highlightedItem);
945
+ if (this.highlightedItem) {
946
+ this._selectListItem(this.highlightedItem);
947
+ }
851
948
  }
852
949
  }, {
853
950
  key: "_searchForCountry",
@@ -883,7 +980,7 @@
883
980
  }, {
884
981
  key: "_updateFlagFromNumber",
885
982
  value: function _updateFlagFromNumber(originalNumber) {
886
- // if we're in nationalMode and we already have US/Canada selected, make sure the number starts
983
+ // if we already have US/Canada selected, make sure the number starts
887
984
  // with a +1 so _getDialCode will be able to extract the area code
888
985
  // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag
889
986
  // from the number), that means we're initialising the plugin with a number that already has a
@@ -891,8 +988,10 @@
891
988
  var number = originalNumber;
892
989
  var selectedDialCode = this.selectedCountryData.dialCode;
893
990
  var isNanp = selectedDialCode === "1";
894
- if (number && this.options.nationalMode && isNanp && number.charAt(0) !== "+") {
895
- if (number.charAt(0) !== "1") number = "1".concat(number);
991
+ if (number && isNanp && number.charAt(0) !== "+") {
992
+ if (number.charAt(0) !== "1") {
993
+ number = "1".concat(number);
994
+ }
896
995
  number = "+".concat(number);
897
996
  }
898
997
  // if separateDialCode enabled, then consider the selected dial code to be part of the number
@@ -953,11 +1052,15 @@
953
1052
  key: "_highlightListItem",
954
1053
  value: function _highlightListItem(listItem, shouldFocus) {
955
1054
  var prevItem = this.highlightedItem;
956
- if (prevItem) prevItem.classList.remove("iti__highlight");
1055
+ if (prevItem) {
1056
+ prevItem.classList.remove("iti__highlight");
1057
+ }
957
1058
  this.highlightedItem = listItem;
958
1059
  this.highlightedItem.classList.add("iti__highlight");
959
1060
  this.selectedFlag.setAttribute("aria-activedescendant", listItem.getAttribute("id"));
960
- if (shouldFocus) this.highlightedItem.focus();
1061
+ if (shouldFocus) {
1062
+ this.highlightedItem.focus();
1063
+ }
961
1064
  }
962
1065
  }, {
963
1066
  key: "_getCountryData",
@@ -983,10 +1086,14 @@
983
1086
  if (this.selectedCountryData.iso2) {
984
1087
  this.defaultCountry = this.selectedCountryData.iso2;
985
1088
  }
986
- this.selectedFlagInner.setAttribute("class", "iti__flag iti__".concat(countryCode));
1089
+ if (this.options.showFlags) {
1090
+ this.selectedFlagInner.setAttribute("class", "iti__flag iti__".concat(countryCode));
1091
+ }
987
1092
  // update the selected country's title attribute
988
- var title = countryCode ? "".concat(this.selectedCountryData.name, ": +").concat(this.selectedCountryData.dialCode) : "Unknown";
989
- this.selectedFlag.setAttribute("title", title);
1093
+ if (this.selectedFlag) {
1094
+ var title = countryCode ? "".concat(this.selectedCountryData.name, ": +").concat(this.selectedCountryData.dialCode) : "Unknown";
1095
+ this.selectedFlag.setAttribute("title", title);
1096
+ }
990
1097
  if (this.options.separateDialCode) {
991
1098
  var dialCode = this.selectedCountryData.dialCode ? "+".concat(this.selectedCountryData.dialCode) : "";
992
1099
  this.selectedDialCode.innerHTML = dialCode;
@@ -1054,8 +1161,8 @@
1054
1161
  this._updateDialCode(listItem.getAttribute("data-dial-code"));
1055
1162
  // focus the input
1056
1163
  this.telInput.focus();
1057
- // put cursor at end - this fix is required for FF and IE11 (with nationalMode=false i.e. auto
1058
- // inserting dial code), who try to put the cursor at the beginning the first time
1164
+ // put cursor at end - this fix is required for FF and IE11 (with auto inserting dial code),
1165
+ // who try to put the cursor at the beginning the first time
1059
1166
  var len = this.telInput.value.length;
1060
1167
  this.telInput.setSelectionRange(len, len);
1061
1168
  if (flagChanged) {
@@ -1077,8 +1184,12 @@
1077
1184
  this.countryList.removeEventListener("click", this._handleClickCountryList);
1078
1185
  // remove menu from container
1079
1186
  if (this.options.dropdownContainer) {
1080
- if (!this.isMobile) window.removeEventListener("scroll", this._handleWindowScroll);
1081
- if (this.dropdown.parentNode) this.dropdown.parentNode.removeChild(this.dropdown);
1187
+ if (!this.isMobile) {
1188
+ window.removeEventListener("scroll", this._handleWindowScroll);
1189
+ }
1190
+ if (this.dropdown.parentNode) {
1191
+ this.dropdown.parentNode.removeChild(this.dropdown);
1192
+ }
1082
1193
  }
1083
1194
  this._trigger("close:countrydropdown");
1084
1195
  }
@@ -1098,11 +1209,15 @@
1098
1209
  var middleOffset = containerHeight / 2 - elementHeight / 2;
1099
1210
  if (elementTop < containerTop) {
1100
1211
  // scroll up
1101
- if (middle) newScrollTop -= middleOffset;
1212
+ if (middle) {
1213
+ newScrollTop -= middleOffset;
1214
+ }
1102
1215
  container.scrollTop = newScrollTop;
1103
1216
  } else if (elementBottom > containerBottom) {
1104
1217
  // scroll down
1105
- if (middle) newScrollTop += middleOffset;
1218
+ if (middle) {
1219
+ newScrollTop += middleOffset;
1220
+ }
1106
1221
  var heightDifference = containerHeight - elementHeight;
1107
1222
  container.scrollTop = newScrollTop - heightDifference;
1108
1223
  }
@@ -1115,7 +1230,7 @@
1115
1230
  var newDialCode = "+".concat(newDialCodeBare);
1116
1231
  var newNumber;
1117
1232
  if (inputVal.charAt(0) === "+") {
1118
- // there's a plus so we're dealing with a replacement (doesn't matter if nationalMode or not)
1233
+ // there's a plus so we're dealing with a replacement
1119
1234
  var prevDialCode = this._getDialCode(inputVal);
1120
1235
  if (prevDialCode) {
1121
1236
  // current number contains a valid dial code, so replace it
@@ -1249,13 +1364,19 @@
1249
1364
  this.flagsContainer.removeEventListener("keydown", this._handleFlagsContainerKeydown);
1250
1365
  // label click hack
1251
1366
  var label = this._getClosestLabel();
1252
- if (label) label.removeEventListener("click", this._handleLabelClick);
1367
+ if (label) {
1368
+ label.removeEventListener("click", this._handleLabelClick);
1369
+ }
1253
1370
  }
1254
1371
  // unbind hiddenInput listeners
1255
- if (this.hiddenInput && form) form.removeEventListener("submit", this._handleHiddenInputSubmit);
1372
+ if (this.hiddenInput && form) {
1373
+ form.removeEventListener("submit", this._handleHiddenInputSubmit);
1374
+ }
1256
1375
  // unbind autoInsertDialCode listeners
1257
1376
  if (this.options.autoInsertDialCode) {
1258
- if (form) form.removeEventListener("submit", this._handleSubmitOrBlurEvent);
1377
+ if (form) {
1378
+ form.removeEventListener("submit", this._handleSubmitOrBlurEvent);
1379
+ }
1259
1380
  this.telInput.removeEventListener("blur", this._handleSubmitOrBlurEvent);
1260
1381
  }
1261
1382
  // unbind key events, and cut/paste events
@@ -1313,15 +1434,14 @@
1313
1434
  key: "isValidNumber",
1314
1435
  value: function isValidNumber() {
1315
1436
  var val = this._getFullNumber().trim();
1316
- var countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : "";
1317
- return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null;
1437
+ return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, this.selectedCountryData.iso2) : null;
1318
1438
  }
1319
1439
  }, {
1320
1440
  key: "setCountry",
1321
1441
  value: function setCountry(originalCountryCode) {
1322
1442
  var countryCode = originalCountryCode.toLowerCase();
1323
1443
  // check if already selected
1324
- if (!this.selectedFlagInner.classList.contains("iti__".concat(countryCode))) {
1444
+ if (this.selectedCountryData.iso2 !== countryCode) {
1325
1445
  this._setFlag(countryCode);
1326
1446
  this._updateDialCode(this.selectedCountryData.dialCode);
1327
1447
  this._triggerCountryChange();
@@ -1360,11 +1480,15 @@
1360
1480
  var script = document.createElement("script");
1361
1481
  script.onload = function() {
1362
1482
  forEachInstance("handleUtils");
1363
- if (handleSuccess) handleSuccess();
1483
+ if (handleSuccess) {
1484
+ handleSuccess();
1485
+ }
1364
1486
  };
1365
1487
  script.onerror = function() {
1366
1488
  forEachInstance("rejectUtilsScriptPromise");
1367
- if (handleFailure) handleFailure();
1489
+ if (handleFailure) {
1490
+ handleFailure();
1491
+ }
1368
1492
  };
1369
1493
  script.className = "iti-load-utils";
1370
1494
  script.async = true;
@@ -1393,7 +1517,7 @@
1393
1517
  // default options
1394
1518
  intlTelInputGlobals.defaults = defaults;
1395
1519
  // version
1396
- intlTelInputGlobals.version = "18.0.3";
1520
+ intlTelInputGlobals.version = "18.1.1";
1397
1521
  var pluginName = "intlTelInput";
1398
1522
  // A really lightweight plugin wrapper around the constructor,
1399
1523
  // preventing against multiple instantiations