intl-tel-input 18.5.3 → 19.0.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 (34) hide show
  1. package/README.md +42 -28
  2. package/build/css/demo.css +1 -1
  3. package/build/css/intlTelInput.css +29 -20
  4. package/build/js/data.js +1 -1
  5. package/build/js/data.min.js +1 -1
  6. package/build/js/intlTelInput-jquery.js +158 -151
  7. package/build/js/intlTelInput-jquery.min.js +3 -3
  8. package/build/js/intlTelInput.js +158 -151
  9. package/build/js/intlTelInput.min.js +3 -3
  10. package/composer.json +1 -1
  11. package/demo.html +5 -5
  12. package/grunt/replace.js +1 -7
  13. package/package.json +1 -1
  14. package/spec.html +6 -4
  15. package/src/css/demo.scss +1 -1
  16. package/src/css/intlTelInput.scss +42 -30
  17. package/src/js/intlTelInput.js +76 -125
  18. package/src/spec/helpers/helpers.js +23 -10
  19. package/src/spec/tests/core/countrychangeEvent.js +1 -1
  20. package/src/spec/tests/core/dropdownShortcuts.js +3 -2
  21. package/src/spec/tests/core/initialValues.js +2 -3
  22. package/src/spec/tests/methods/getSelectedCountryData.js +1 -1
  23. package/src/spec/tests/methods/isValidNumber.js +15 -32
  24. package/src/spec/tests/methods/isValidNumberPrecise.js +73 -0
  25. package/src/spec/tests/methods/setCountry.js +4 -4
  26. package/src/spec/tests/options/allowDropdown.js +3 -3
  27. package/src/spec/tests/options/autoInsertDialCode.js +1 -3
  28. package/src/spec/tests/options/autoPlaceholder.js +5 -5
  29. package/src/spec/tests/options/{customContainer.js → containerClass.js} +3 -3
  30. package/src/spec/tests/options/countrySearch.js +63 -0
  31. package/src/spec/tests/options/customPlaceholder.js +1 -1
  32. package/src/spec/tests/options/preferredCountries.js +3 -1
  33. package/src/spec/tests/options/{separateDialCode.js → showSelectedDialCode.js} +7 -7
  34. package/src/spec/tests/methods/isPossibleNumber.js +0 -56
@@ -1,5 +1,5 @@
1
1
  /*
2
- * International Telephone Input v18.5.3
2
+ * International Telephone Input v19.0.1
3
3
  * https://github.com/jackocnr/intl-tel-input.git
4
4
  * Licensed under the MIT license
5
5
  */
@@ -71,6 +71,52 @@
71
71
  }
72
72
  return obj;
73
73
  }
74
+ function _slicedToArray(arr, i) {
75
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
76
+ }
77
+ function _nonIterableRest() {
78
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
79
+ }
80
+ function _unsupportedIterableToArray(o, minLen) {
81
+ if (!o) return;
82
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
83
+ var n = Object.prototype.toString.call(o).slice(8, -1);
84
+ if (n === "Object" && o.constructor) n = o.constructor.name;
85
+ if (n === "Map" || n === "Set") return Array.from(o);
86
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
87
+ }
88
+ function _arrayLikeToArray(arr, len) {
89
+ if (len == null || len > arr.length) len = arr.length;
90
+ for (var i = 0, arr2 = new Array(len); i < len; i++) {
91
+ arr2[i] = arr[i];
92
+ }
93
+ return arr2;
94
+ }
95
+ function _iterableToArrayLimit(arr, i) {
96
+ var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
97
+ if (null != _i) {
98
+ var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1;
99
+ try {
100
+ if (_x = (_i = _i.call(arr)).next, 0 === i) {
101
+ if (Object(_i) !== _i) return;
102
+ _n = !1;
103
+ } else for (;!(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) {
104
+ }
105
+ } catch (err) {
106
+ _d = !0, _e = err;
107
+ } finally {
108
+ try {
109
+ if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
110
+ } finally {
111
+ if (_d) throw _e;
112
+ }
113
+ }
114
+ return _arr;
115
+ }
116
+ }
117
+ function _arrayWithHoles(arr) {
118
+ if (Array.isArray(arr)) return arr;
119
+ }
74
120
  function _classCallCheck(instance, Constructor) {
75
121
  if (!(instance instanceof Constructor)) {
76
122
  throw new TypeError("Cannot call a class as a function");
@@ -132,9 +178,9 @@
132
178
  // add a placeholder in the input with an example number for the selected country
133
179
  autoPlaceholder: "polite",
134
180
  // add a country search input at the top of the dropdown
135
- countrySearch: false,
181
+ countrySearch: true,
136
182
  // modify the parentClass
137
- customContainer: "",
183
+ containerClass: "",
138
184
  // modify the auto placeholder
139
185
  customPlaceholder: null,
140
186
  // append menu to specified element
@@ -142,29 +188,29 @@
142
188
  // don't display these countries
143
189
  excludeCountries: [],
144
190
  // fix the dropdown width to the input width (rather than being as wide as the longest country name)
145
- fixDropdownWidth: false,
191
+ fixDropdownWidth: true,
146
192
  // format the input value during initialisation and on setNumber
147
193
  formatOnDisplay: true,
148
194
  // geoIp lookup function
149
195
  geoIpLookup: null,
150
196
  // inject a hidden input with this name, and on submit, populate it with the result of getNumber
151
- hiddenInput: "",
197
+ hiddenInput: null,
198
+ // internationalise the plugin text e.g. search input placeholder, country names
199
+ i18n: {},
152
200
  // initial country
153
201
  initialCountry: "",
154
- // localized country names e.g. { 'de': 'Deutschland' }
155
- localizedCountries: null,
156
202
  // national vs international formatting for numbers e.g. placeholders and displaying existing numbers
157
203
  nationalMode: true,
158
204
  // display only these countries
159
205
  onlyCountries: [],
160
206
  // number type to use for placeholders
161
207
  placeholderNumberType: "MOBILE",
162
- // the countries at the top of the list. defaults to united states and united kingdom
163
- preferredCountries: [ "us", "gb" ],
164
- // display the country dial code next to the selected flag
165
- separateDialCode: false,
166
- // option to hide the flags - must be used with separateDialCode, or allowDropdown=false
208
+ // the countries at the top of the list
209
+ preferredCountries: [],
210
+ // option to hide the flags - must be used with showSelectedDialCode, or allowDropdown=false
167
211
  showFlags: true,
212
+ // display the international dial code next to the selected flag
213
+ showSelectedDialCode: false,
168
214
  // use full screen popup instead of dropdown for country list
169
215
  useFullscreenPopup: typeof navigator !== "undefined" && typeof window !== "undefined" ? // we cannot just test screen size as some smartphones/website meta tags will report desktop
170
216
  // resolutions
@@ -175,43 +221,31 @@
175
221
  };
176
222
  // https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#Non-geographic_area_codes
177
223
  var regionlessNanpNumbers = [ "800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889" ];
178
- // utility function to iterate over an object. can't use Object.entries or native forEach because
179
- // of IE11
180
- var forEachProp = function forEachProp(obj, callback) {
181
- var keys = Object.keys(obj);
182
- for (var i = 0; i < keys.length; i++) {
183
- callback(keys[i], obj[keys[i]]);
184
- }
185
- };
186
224
  // run a method on each instance of the plugin
187
225
  var forEachInstance = function forEachInstance(method) {
188
- forEachProp(window.intlTelInputGlobals.instances, function(key) {
189
- window.intlTelInputGlobals.instances[key][method]();
226
+ var instances = window.intlTelInputGlobals.instances;
227
+ Object.values(instances).forEach(function(instance) {
228
+ return instance[method]();
190
229
  });
191
230
  };
192
231
  // this is our plugin class that we will create an instance of
193
232
  // eslint-disable-next-line no-unused-vars
194
233
  var Iti = /*#__PURE__*/ function() {
195
- function Iti(input, options) {
196
- var _this = this;
234
+ function Iti(input) {
235
+ var customOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
197
236
  _classCallCheck(this, Iti);
198
237
  this.id = id++;
199
238
  this.telInput = input;
200
239
  this.activeItem = null;
201
240
  this.highlightedItem = null;
202
241
  // process specified options / defaults
203
- // alternative to Object.assign, which isn't supported by IE11
204
- var customOptions = options || {};
205
- this.options = {};
206
- forEachProp(defaults, function(key, value) {
207
- _this.options[key] = customOptions.hasOwnProperty(key) ? customOptions[key] : value;
208
- });
242
+ this.options = Object.assign({}, defaults, customOptions);
209
243
  this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder"));
210
244
  }
211
245
  _createClass(Iti, [ {
212
246
  key: "_init",
213
247
  value: function _init() {
214
- var _this2 = this;
248
+ var _this = this;
215
249
  // if showing fullscreen popup, do not fix the width
216
250
  if (this.options.useFullscreenPopup) {
217
251
  this.options.fixDropdownWidth = false;
@@ -224,13 +258,13 @@
224
258
  if (this.options.nationalMode) {
225
259
  this.options.autoInsertDialCode = false;
226
260
  }
227
- // if separateDialCode enabled, do not insert dial codes
228
- if (this.options.separateDialCode) {
261
+ // if showSelectedDialCode enabled, do not insert dial codes
262
+ if (this.options.showSelectedDialCode) {
229
263
  this.options.autoInsertDialCode = false;
230
264
  }
231
265
  // force showFlags=true if there's a dropdown and we're not displaying the dial code,
232
266
  // as otherwise you just have a down arrow on it's own which doesn't make sense
233
- var forceShowFlags = this.options.allowDropdown && !this.options.separateDialCode;
267
+ var forceShowFlags = this.options.allowDropdown && !this.options.showSelectedDialCode;
234
268
  if (!this.options.showFlags && forceShowFlags) {
235
269
  this.options.showFlags = true;
236
270
  }
@@ -245,12 +279,12 @@
245
279
  // complete
246
280
  if (typeof Promise !== "undefined") {
247
281
  var autoCountryPromise = new Promise(function(resolve, reject) {
248
- _this2.resolveAutoCountryPromise = resolve;
249
- _this2.rejectAutoCountryPromise = reject;
282
+ _this.resolveAutoCountryPromise = resolve;
283
+ _this.rejectAutoCountryPromise = reject;
250
284
  });
251
285
  var utilsScriptPromise = new Promise(function(resolve, reject) {
252
- _this2.resolveUtilsScriptPromise = resolve;
253
- _this2.rejectUtilsScriptPromise = reject;
286
+ _this.resolveUtilsScriptPromise = resolve;
287
+ _this.rejectUtilsScriptPromise = reject;
254
288
  });
255
289
  this.promise = Promise.all([ autoCountryPromise, utilsScriptPromise ]);
256
290
  } else {
@@ -281,12 +315,10 @@
281
315
  this._processCountryCodes();
282
316
  // process the preferredCountries
283
317
  this._processPreferredCountries();
284
- // translate countries according to localizedCountries option
285
- if (this.options.localizedCountries) {
286
- this._translateCountriesByLocale();
287
- }
318
+ // translate country names according to i18n option
319
+ this._translateCountryNames();
288
320
  // sort countries by name
289
- if (this.options.onlyCountries.length || this.options.localizedCountries) {
321
+ if (this.options.onlyCountries.length || this.options.i18n) {
290
322
  this.countries.sort(this._countryNameSort);
291
323
  }
292
324
  }
@@ -331,12 +363,12 @@
331
363
  }
332
364
  }
333
365
  }, {
334
- key: "_translateCountriesByLocale",
335
- value: function _translateCountriesByLocale() {
366
+ key: "_translateCountryNames",
367
+ value: function _translateCountryNames() {
336
368
  for (var i = 0; i < this.countries.length; i++) {
337
369
  var iso = this.countries[i].iso2.toLowerCase();
338
- if (this.options.localizedCountries.hasOwnProperty(iso)) {
339
- this.countries[i].name = this.options.localizedCountries[iso];
370
+ if (this.options.i18n.hasOwnProperty(iso)) {
371
+ this.countries[i].name = this.options.i18n[iso];
340
372
  }
341
373
  }
342
374
  }
@@ -409,7 +441,8 @@
409
441
  value: function _createEl(name, attrs, container) {
410
442
  var el = document.createElement(name);
411
443
  if (attrs) {
412
- forEachProp(attrs, function(key, value) {
444
+ Object.entries(attrs).forEach(function(_ref) {
445
+ var _ref2 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1];
413
446
  return el.setAttribute(key, value);
414
447
  });
415
448
  }
@@ -429,27 +462,30 @@
429
462
  if (!this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete"))) {
430
463
  this.telInput.setAttribute("autocomplete", "off");
431
464
  }
432
- 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, fixDropdownWidth = _this$options.fixDropdownWidth, useFullscreenPopup = _this$options.useFullscreenPopup, countrySearch = _this$options.countrySearch;
465
+ var _this$options = this.options, allowDropdown = _this$options.allowDropdown, showSelectedDialCode = _this$options.showSelectedDialCode, showFlags = _this$options.showFlags, containerClass = _this$options.containerClass, hiddenInput = _this$options.hiddenInput, dropdownContainer = _this$options.dropdownContainer, fixDropdownWidth = _this$options.fixDropdownWidth, useFullscreenPopup = _this$options.useFullscreenPopup, countrySearch = _this$options.countrySearch;
433
466
  // containers (mostly for positioning)
434
467
  var parentClass = "iti";
435
468
  if (allowDropdown) {
436
469
  parentClass += " iti--allow-dropdown";
437
470
  }
438
- if (separateDialCode) {
439
- parentClass += " iti--separate-dial-code";
471
+ if (showSelectedDialCode) {
472
+ parentClass += " iti--show-selected-dial-code";
440
473
  }
441
474
  if (showFlags) {
442
475
  parentClass += " iti--show-flags";
443
476
  }
444
- if (customContainer) {
445
- parentClass += " ".concat(customContainer);
477
+ if (containerClass) {
478
+ parentClass += " ".concat(containerClass);
479
+ }
480
+ if (!useFullscreenPopup) {
481
+ parentClass += " iti--inline-dropdown";
446
482
  }
447
483
  var wrapper = this._createEl("div", {
448
484
  "class": parentClass
449
485
  });
450
486
  this.telInput.parentNode.insertBefore(wrapper, this.telInput);
451
- // only hide the flagsContainer if allowDropdown, showFlags and separateDialCode are all false
452
- var showFlagsContainer = allowDropdown || showFlags || separateDialCode;
487
+ // only hide the flagsContainer if allowDropdown, showFlags and showSelectedDialCode are all false
488
+ var showFlagsContainer = allowDropdown || showFlags || showSelectedDialCode;
453
489
  if (showFlagsContainer) {
454
490
  this.flagsContainer = this._createEl("div", {
455
491
  "class": "iti__flag-container"
@@ -467,7 +503,7 @@
467
503
  "aria-haspopup": "listbox",
468
504
  "aria-controls": "iti-".concat(this.id, "__country-listbox"),
469
505
  "aria-expanded": "false",
470
- "aria-label": "Telephone country code"
506
+ "aria-label": this.options.i18n.selectedCountryAriaLabel || "Selected country"
471
507
  }), this.flagsContainer);
472
508
  }
473
509
  if (showFlags) {
@@ -478,7 +514,7 @@
478
514
  if (this.selectedFlag && this.telInput.disabled) {
479
515
  this.selectedFlag.setAttribute("aria-disabled", "true");
480
516
  }
481
- if (separateDialCode) {
517
+ if (showSelectedDialCode) {
482
518
  this.selectedDialCode = this._createEl("div", {
483
519
  "class": "iti__selected-dial-code"
484
520
  }, this.selectedFlag);
@@ -499,7 +535,7 @@
499
535
  this.searchInput = this._createEl("input", {
500
536
  type: "text",
501
537
  "class": "iti__search-input",
502
- placeholder: "Search"
538
+ placeholder: this.options.i18n.searchPlaceholder || "Search"
503
539
  }, this.dropdownContent);
504
540
  }
505
541
  // country list: preferred countries, then divider, then all countries
@@ -507,7 +543,7 @@
507
543
  "class": "iti__country-list",
508
544
  id: "iti-".concat(this.id, "__country-listbox"),
509
545
  role: "listbox",
510
- "aria-label": "List of countries"
546
+ "aria-label": this.options.i18n.countryListAriaLabel || "List of countries"
511
547
  }, this.dropdownContent);
512
548
  if (this.preferredCountries.length && !countrySearch) {
513
549
  this._appendListItems(this.preferredCountries, "iti__preferred", true);
@@ -522,6 +558,8 @@
522
558
  var dropdownClasses = "iti iti--container";
523
559
  if (useFullscreenPopup) {
524
560
  dropdownClasses += " iti--fullscreen-popup";
561
+ } else {
562
+ dropdownClasses += " iti--inline-dropdown";
525
563
  }
526
564
  if (countrySearch) {
527
565
  dropdownClasses += " iti--country-search";
@@ -535,16 +573,8 @@
535
573
  }
536
574
  }
537
575
  if (hiddenInput) {
538
- var hiddenInputName = hiddenInput;
539
- var name = this.telInput.getAttribute("name");
540
- if (name) {
541
- var i = name.lastIndexOf("[");
542
- // if input name contains square brackets, then give the hidden input the same name,
543
- // replacing the contents of the last set of brackets with the given hiddenInput name
544
- if (i !== -1) {
545
- hiddenInputName = "".concat(name.substr(0, i), "[").concat(hiddenInputName, "]");
546
- }
547
- }
576
+ var telInputName = this.telInput.getAttribute("name");
577
+ var hiddenInputName = hiddenInput(telInputName);
548
578
  this.hiddenInput = this._createEl("input", {
549
579
  type: "hidden",
550
580
  name: hiddenInputName
@@ -642,39 +672,30 @@
642
672
  }, {
643
673
  key: "_initHiddenInputListener",
644
674
  value: function _initHiddenInputListener() {
645
- var _this3 = this;
675
+ var _this2 = this;
646
676
  this._handleHiddenInputSubmit = function() {
647
- _this3.hiddenInput.value = _this3.getNumber();
677
+ _this2.hiddenInput.value = _this2.getNumber();
648
678
  };
649
679
  if (this.telInput.form) {
650
680
  this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit);
651
681
  }
652
682
  }
653
- }, {
654
- key: "_getClosestLabel",
655
- value: function _getClosestLabel() {
656
- var el = this.telInput;
657
- while (el && el.tagName !== "LABEL") {
658
- el = el.parentNode;
659
- }
660
- return el;
661
- }
662
683
  }, {
663
684
  key: "_initDropdownListeners",
664
685
  value: function _initDropdownListeners() {
665
- var _this4 = this;
686
+ var _this3 = this;
666
687
  // hack for input nested inside label (which is valid markup): clicking the selected-flag to
667
688
  // open the dropdown would then automatically trigger a 2nd click on the input which would
668
689
  // close it again
669
690
  this._handleLabelClick = function(e) {
670
691
  // if the dropdown is closed, then focus the input, else ignore the click
671
- if (_this4.dropdownContent.classList.contains("iti__hide")) {
672
- _this4.telInput.focus();
692
+ if (_this3.dropdownContent.classList.contains("iti__hide")) {
693
+ _this3.telInput.focus();
673
694
  } else {
674
695
  e.preventDefault();
675
696
  }
676
697
  };
677
- var label = this._getClosestLabel();
698
+ var label = this.telInput.closest("label");
678
699
  if (label) {
679
700
  label.addEventListener("click", this._handleLabelClick);
680
701
  }
@@ -683,24 +704,24 @@
683
704
  // only intercept this event if we're opening the dropdown
684
705
  // else let it bubble up to the top ("click-off-to-close" listener)
685
706
  // we cannot just stopPropagation as it may be needed to close another instance
686
- if (_this4.dropdownContent.classList.contains("iti__hide") && !_this4.telInput.disabled && !_this4.telInput.readOnly) {
687
- _this4._showDropdown();
707
+ if (_this3.dropdownContent.classList.contains("iti__hide") && !_this3.telInput.disabled && !_this3.telInput.readOnly) {
708
+ _this3._showDropdown();
688
709
  }
689
710
  };
690
711
  this.selectedFlag.addEventListener("click", this._handleClickSelectedFlag);
691
712
  // open dropdown if selected flag is focused and they press up/down/space/enter
692
713
  this._handleFlagsContainerKeydown = function(e) {
693
- var isDropdownHidden = _this4.dropdownContent.classList.contains("iti__hide");
714
+ var isDropdownHidden = _this3.dropdownContent.classList.contains("iti__hide");
694
715
  if (isDropdownHidden && [ "ArrowUp", "ArrowDown", " ", "Enter" ].includes(e.key)) {
695
716
  // prevent form from being submitted if "ENTER" was pressed
696
717
  e.preventDefault();
697
718
  // prevent event from being handled again by document
698
719
  e.stopPropagation();
699
- _this4._showDropdown();
720
+ _this3._showDropdown();
700
721
  }
701
722
  // allow navigation from dropdown to input on TAB
702
723
  if (e.key === "Tab") {
703
- _this4._closeDropdown();
724
+ _this3._closeDropdown();
704
725
  }
705
726
  };
706
727
  this.flagsContainer.addEventListener("keydown", this._handleFlagsContainerKeydown);
@@ -708,7 +729,7 @@
708
729
  }, {
709
730
  key: "_initRequests",
710
731
  value: function _initRequests() {
711
- var _this5 = this;
732
+ var _this4 = this;
712
733
  // if the user has specified the path to the utils script, fetch it on window.load, else resolve
713
734
  if (this.options.utilsScript && !window.intlTelInputUtils) {
714
735
  // if the plugin is being initialised after the window.load event has already been fired
@@ -717,7 +738,7 @@
717
738
  } else {
718
739
  // wait until the load event so we don't block any other requests e.g. the flags image
719
740
  window.addEventListener("load", function() {
720
- window.intlTelInputGlobals.loadUtils(_this5.options.utilsScript);
741
+ window.intlTelInputGlobals.loadUtils(_this4.options.utilsScript);
721
742
  });
722
743
  }
723
744
  } else {
@@ -762,18 +783,18 @@
762
783
  }, {
763
784
  key: "_initKeyListeners",
764
785
  value: function _initKeyListeners() {
765
- var _this6 = this;
786
+ var _this5 = this;
766
787
  // update flag on keyup
767
788
  this._handleKeyupEvent = function() {
768
- if (_this6._updateFlagFromNumber(_this6.telInput.value)) {
769
- _this6._triggerCountryChange();
789
+ if (_this5._updateFlagFromNumber(_this5.telInput.value)) {
790
+ _this5._triggerCountryChange();
770
791
  }
771
792
  };
772
793
  this.telInput.addEventListener("keyup", this._handleKeyupEvent);
773
794
  // update flag on cut/paste events (now supported in all major browsers)
774
795
  this._handleClipboardEvent = function() {
775
796
  // hack because "paste" event is fired before input is updated
776
- setTimeout(_this6._handleKeyupEvent);
797
+ setTimeout(_this5._handleKeyupEvent);
777
798
  };
778
799
  this.telInput.addEventListener("cut", this._handleClipboardEvent);
779
800
  this.telInput.addEventListener("paste", this._handleClipboardEvent);
@@ -787,10 +808,10 @@
787
808
  }, {
788
809
  key: "_initBlurListeners",
789
810
  value: function _initBlurListeners() {
790
- var _this7 = this;
811
+ var _this6 = this;
791
812
  // on blur or form submit: if just a dial code then remove it
792
813
  this._handleSubmitOrBlurEvent = function() {
793
- _this7._removeEmptyDialCode();
814
+ _this6._removeEmptyDialCode();
794
815
  };
795
816
  if (this.telInput.form) {
796
817
  this.telInput.form.addEventListener("submit", this._handleSubmitOrBlurEvent);
@@ -816,10 +837,10 @@
816
837
  }, {
817
838
  key: "_trigger",
818
839
  value: function _trigger(name) {
819
- // have to use old school document.createEvent as IE11 doesn't support `new Event()` syntax
820
- var e = document.createEvent("Event");
821
- e.initEvent(name, true, true);
822
- // can bubble, and is cancellable
840
+ var e = new Event(name, {
841
+ bubbles: true,
842
+ cancelable: true
843
+ });
823
844
  this.telInput.dispatchEvent(e);
824
845
  }
825
846
  }, {
@@ -858,14 +879,14 @@
858
879
  }, {
859
880
  key: "_setDropdownPosition",
860
881
  value: function _setDropdownPosition() {
861
- var _this8 = this;
882
+ var _this7 = this;
862
883
  if (this.options.dropdownContainer) {
863
884
  this.options.dropdownContainer.appendChild(this.dropdown);
864
885
  }
865
886
  if (!this.options.useFullscreenPopup) {
866
887
  var pos = this.telInput.getBoundingClientRect();
867
888
  // windowTop from https://stackoverflow.com/a/14384091/217866
868
- var windowTop = window.pageYOffset || document.documentElement.scrollTop;
889
+ var windowTop = document.documentElement.scrollTop;
869
890
  var inputTop = pos.top + windowTop;
870
891
  var dropdownHeight = this.dropdownContent.offsetHeight;
871
892
  // dropdownFitsBelow = (dropdownBottom < windowBottom)
@@ -886,41 +907,31 @@
886
907
  this.dropdown.style.left = "".concat(pos.left + document.body.scrollLeft, "px");
887
908
  // close menu on window scroll
888
909
  this._handleWindowScroll = function() {
889
- return _this8._closeDropdown();
910
+ return _this7._closeDropdown();
890
911
  };
891
912
  window.addEventListener("scroll", this._handleWindowScroll);
892
913
  }
893
914
  }
894
915
  }
895
- }, {
896
- key: "_getClosestListItem",
897
- value: function _getClosestListItem(target) {
898
- var el = target;
899
- while (el && el !== this.countryList && !el.classList.contains("iti__country")) {
900
- el = el.parentNode;
901
- }
902
- // if we reached the countryList element, then return null
903
- return el === this.countryList ? null : el;
904
- }
905
916
  }, {
906
917
  key: "_bindDropdownListeners",
907
918
  value: function _bindDropdownListeners() {
908
- var _this9 = this;
919
+ var _this8 = this;
909
920
  // when mouse over a list item, just highlight that one
910
921
  // we add the class "highlight", so if they hit "enter" we know which one to select
911
922
  this._handleMouseoverCountryList = function(e) {
912
923
  // handle event delegation, as we're listening for this event on the countryList
913
- var listItem = _this9._getClosestListItem(e.target);
924
+ var listItem = e.target.closest(".iti__country");
914
925
  if (listItem) {
915
- _this9._highlightListItem(listItem, false);
926
+ _this8._highlightListItem(listItem, false);
916
927
  }
917
928
  };
918
929
  this.countryList.addEventListener("mouseover", this._handleMouseoverCountryList);
919
930
  // listen for country selection
920
931
  this._handleClickCountryList = function(e) {
921
- var listItem = _this9._getClosestListItem(e.target);
932
+ var listItem = e.target.closest(".iti__country");
922
933
  if (listItem) {
923
- _this9._selectListItem(listItem);
934
+ _this8._selectListItem(listItem);
924
935
  }
925
936
  };
926
937
  this.countryList.addEventListener("click", this._handleClickCountryList);
@@ -930,7 +941,7 @@
930
941
  var isOpening = true;
931
942
  this._handleClickOffToClose = function() {
932
943
  if (!isOpening) {
933
- _this9._closeDropdown();
944
+ _this8._closeDropdown();
934
945
  }
935
946
  isOpening = false;
936
947
  };
@@ -949,23 +960,23 @@
949
960
  e.stopPropagation();
950
961
  // up and down to navigate
951
962
  if (e.key === "ArrowUp" || e.key === "ArrowDown") {
952
- _this9._handleUpDownKey(e.key);
963
+ _this8._handleUpDownKey(e.key);
953
964
  } else if (e.key === "Enter") {
954
- _this9._handleEnterKey();
965
+ _this8._handleEnterKey();
955
966
  } else if (e.key === "Escape") {
956
- _this9._closeDropdown();
967
+ _this8._closeDropdown();
957
968
  }
958
969
  }
959
970
  // alpha chars to perform search
960
971
  // regex allows one latin alpha char or space, based on https://stackoverflow.com/a/26900132/217866)
961
- if (!_this9.options.countrySearch && /^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(e.key)) {
972
+ if (!_this8.options.countrySearch && /^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(e.key)) {
962
973
  e.stopPropagation();
963
974
  // jump to countries that start with the query string
964
975
  if (queryTimer) {
965
976
  clearTimeout(queryTimer);
966
977
  }
967
978
  query += e.key.toLowerCase();
968
- _this9._searchForCountry(query);
979
+ _this8._searchForCountry(query);
969
980
  // if the timer hits 1 second, reset the query
970
981
  queryTimer = setTimeout(function() {
971
982
  query = "";
@@ -975,11 +986,11 @@
975
986
  document.addEventListener("keydown", this._handleKeydownOnDropdown);
976
987
  if (this.options.countrySearch) {
977
988
  var doFilter = function doFilter() {
978
- var inputQuery = _this9.searchInput.value.trim();
989
+ var inputQuery = _this8.searchInput.value.trim();
979
990
  if (inputQuery) {
980
- _this9._filterCountries(inputQuery.toLowerCase());
991
+ _this8._filterCountries(inputQuery.toLowerCase());
981
992
  } else {
982
- _this9._filterCountries(null, true);
993
+ _this8._filterCountries(null, true);
983
994
  }
984
995
  };
985
996
  var keyupTimer = null;
@@ -1010,7 +1021,7 @@
1010
1021
  var c = this.countries[i];
1011
1022
  var nameLower = c.name.toLowerCase();
1012
1023
  var fullDialCode = "+".concat(c.dialCode);
1013
- if (isReset || nameLower.includes(query) || fullDialCode.includes(query)) {
1024
+ if (isReset || nameLower.includes(query) || fullDialCode.includes(query) || c.iso2.includes(query)) {
1014
1025
  this.countryList.appendChild(c.node);
1015
1026
  // highlight the first item
1016
1027
  if (isFirst) {
@@ -1072,7 +1083,7 @@
1072
1083
  value: function _updateValFromNumber(fullNumber) {
1073
1084
  var number = fullNumber;
1074
1085
  if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) {
1075
- var useNational = this.options.nationalMode || number.charAt(0) !== "+" && !this.options.separateDialCode;
1086
+ var useNational = this.options.nationalMode || number.charAt(0) !== "+" && !this.options.showSelectedDialCode;
1076
1087
  var _intlTelInputUtils$nu = intlTelInputUtils.numberFormat, NATIONAL = _intlTelInputUtils$nu.NATIONAL, INTERNATIONAL = _intlTelInputUtils$nu.INTERNATIONAL;
1077
1088
  var format = useNational ? NATIONAL : INTERNATIONAL;
1078
1089
  number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format);
@@ -1101,8 +1112,8 @@
1101
1112
  }
1102
1113
  number = "+".concat(number);
1103
1114
  }
1104
- // if separateDialCode enabled, then consider the selected dial code to be part of the number
1105
- if (this.options.separateDialCode && selectedDialCode && number.charAt(0) !== "+") {
1115
+ // if showSelectedDialCode enabled, then consider the selected dial code to be part of the number
1116
+ if (this.options.showSelectedDialCode && selectedDialCode && number.charAt(0) !== "+") {
1106
1117
  number = "+".concat(selectedDialCode).concat(number);
1107
1118
  }
1108
1119
  // try and extract valid dial code from input
@@ -1186,7 +1197,7 @@
1186
1197
  }, {
1187
1198
  key: "_setFlag",
1188
1199
  value: function _setFlag(countryCode) {
1189
- var _this$options3 = this.options, allowDropdown = _this$options3.allowDropdown, separateDialCode = _this$options3.separateDialCode, showFlags = _this$options3.showFlags;
1200
+ var _this$options3 = this.options, allowDropdown = _this$options3.allowDropdown, showSelectedDialCode = _this$options3.showSelectedDialCode, showFlags = _this$options3.showFlags;
1190
1201
  var prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {};
1191
1202
  // do this first as it will throw an error and stop if countryCode is invalid
1192
1203
  this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {};
@@ -1197,8 +1208,8 @@
1197
1208
  if (showFlags) {
1198
1209
  this.selectedFlagInner.setAttribute("class", "iti__flag iti__".concat(countryCode));
1199
1210
  }
1200
- this._setSelectedCountryFlagTitleAttribute(countryCode, separateDialCode);
1201
- if (separateDialCode) {
1211
+ this._setSelectedCountryFlagTitleAttribute(countryCode, showSelectedDialCode);
1212
+ if (showSelectedDialCode) {
1202
1213
  var dialCode = this.selectedCountryData.dialCode ? "+".concat(this.selectedCountryData.dialCode) : "";
1203
1214
  this.selectedDialCode.innerHTML = dialCode;
1204
1215
  // offsetWidth is zero if input is in a hidden container during initialisation
@@ -1232,12 +1243,12 @@
1232
1243
  }
1233
1244
  }, {
1234
1245
  key: "_setSelectedCountryFlagTitleAttribute",
1235
- value: function _setSelectedCountryFlagTitleAttribute(countryCode, separateDialCode) {
1246
+ value: function _setSelectedCountryFlagTitleAttribute(countryCode, showSelectedDialCode) {
1236
1247
  if (!this.selectedFlag) {
1237
1248
  return;
1238
1249
  }
1239
1250
  var title;
1240
- if (countryCode && !separateDialCode) {
1251
+ if (countryCode && !showSelectedDialCode) {
1241
1252
  title = "".concat(this.selectedCountryData.name, ": +").concat(this.selectedCountryData.dialCode);
1242
1253
  } else if (countryCode) {
1243
1254
  // For screen reader output, we don't want to include the dial code in the reader output twice
@@ -1287,10 +1298,6 @@
1287
1298
  this._updateDialCode(listItem.getAttribute("data-dial-code"));
1288
1299
  // focus the input
1289
1300
  this.telInput.focus();
1290
- // put cursor at end - this fix is required for FF and IE11 (with auto inserting dial code),
1291
- // who try to put the cursor at the beginning the first time
1292
- var len = this.telInput.value.length;
1293
- this.telInput.setSelectionRange(len, len);
1294
1301
  if (flagChanged) {
1295
1302
  this._triggerCountryChange();
1296
1303
  }
@@ -1327,7 +1334,7 @@
1327
1334
  value: function _scrollTo(element, middle) {
1328
1335
  var container = this.dropdownContent;
1329
1336
  // windowTop from https://stackoverflow.com/a/14384091/217866
1330
- var windowTop = window.pageYOffset || document.documentElement.scrollTop;
1337
+ var windowTop = document.documentElement.scrollTop;
1331
1338
  var containerHeight = container.offsetHeight;
1332
1339
  var containerTop = container.getBoundingClientRect().top + windowTop;
1333
1340
  var containerBottom = containerTop + containerHeight;
@@ -1422,8 +1429,8 @@
1422
1429
  var dialCode = this.selectedCountryData.dialCode;
1423
1430
  var prefix;
1424
1431
  var numericVal = this._getNumeric(val);
1425
- if (this.options.separateDialCode && val.charAt(0) !== "+" && dialCode && numericVal) {
1426
- // when using separateDialCode, it is visible so is effectively part of the typed number
1432
+ if (this.options.showSelectedDialCode && val.charAt(0) !== "+" && dialCode && numericVal) {
1433
+ // when using showSelectedDialCode, it is visible so is effectively part of the typed number
1427
1434
  prefix = "+".concat(dialCode);
1428
1435
  } else {
1429
1436
  prefix = "";
@@ -1434,7 +1441,7 @@
1434
1441
  key: "_beforeSetNumber",
1435
1442
  value: function _beforeSetNumber(fullNumber) {
1436
1443
  var number = fullNumber;
1437
- if (this.options.separateDialCode) {
1444
+ if (this.options.showSelectedDialCode) {
1438
1445
  var dialCode = this._getDialCode(number);
1439
1446
  // if there is a valid dial code
1440
1447
  if (dialCode) {
@@ -1492,7 +1499,7 @@
1492
1499
  this.selectedFlag.removeEventListener("click", this._handleClickSelectedFlag);
1493
1500
  this.flagsContainer.removeEventListener("keydown", this._handleFlagsContainerKeydown);
1494
1501
  // label click hack
1495
- var label = this._getClosestLabel();
1502
+ var label = this.telInput.closest("label");
1496
1503
  if (label) {
1497
1504
  label.removeEventListener("click", this._handleLabelClick);
1498
1505
  }
@@ -1563,13 +1570,13 @@
1563
1570
  key: "isValidNumber",
1564
1571
  value: function isValidNumber() {
1565
1572
  var val = this._getFullNumber().trim();
1566
- return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, this.selectedCountryData.iso2) : null;
1573
+ return window.intlTelInputUtils ? intlTelInputUtils.isPossibleNumber(val, this.selectedCountryData.iso2) : null;
1567
1574
  }
1568
1575
  }, {
1569
- key: "isPossibleNumber",
1570
- value: function isPossibleNumber() {
1576
+ key: "isValidNumberPrecise",
1577
+ value: function isValidNumberPrecise() {
1571
1578
  var val = this._getFullNumber().trim();
1572
- return window.intlTelInputUtils ? intlTelInputUtils.isPossibleNumber(val, this.selectedCountryData.iso2) : null;
1579
+ return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, this.selectedCountryData.iso2) : null;
1573
1580
  }
1574
1581
  }, {
1575
1582
  key: "setCountry",
@@ -1652,7 +1659,7 @@
1652
1659
  // default options
1653
1660
  intlTelInputGlobals.defaults = defaults;
1654
1661
  // version
1655
- intlTelInputGlobals.version = "18.5.3";
1662
+ intlTelInputGlobals.version = "19.0.1";
1656
1663
  var pluginName = "intlTelInput";
1657
1664
  // A really lightweight plugin wrapper around the constructor,
1658
1665
  // preventing against multiple instantiations