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.
- package/.eslintrc +2 -8
- package/.vscode/settings.json +8 -0
- package/CHANGELOG.md +3 -0
- package/Gruntfile.js +0 -2
- package/README.md +24 -30
- package/build/css/intlTelInput.css +1 -1
- package/build/js/data.js +1 -1
- package/build/js/data.min.js +1 -1
- package/build/js/intlTelInput-jquery.js +213 -89
- package/build/js/intlTelInput-jquery.min.js +3 -3
- package/build/js/intlTelInput.js +213 -89
- package/build/js/intlTelInput.min.js +3 -3
- package/composer.json +1 -1
- package/demo.html +42 -43
- package/demo_rtl.html +21 -23
- package/grunt/template.js +2 -265
- package/package.json +4 -1
- package/src/css/intlTelInput.scss +1 -1
- package/src/js/intlTelInput.js +605 -341
- package/examples/css/countrySync.css +0 -10
- package/examples/css/isValidNumber.css +0 -12
- package/examples/css/prism.css +0 -126
- package/examples/gen/country-sync.html +0 -98
- package/examples/gen/default-country-ip.html +0 -62
- package/examples/gen/display-number.html +0 -47
- package/examples/gen/hidden-input.html +0 -54
- package/examples/gen/init-promise.html +0 -66
- package/examples/gen/is-valid-number.html +0 -86
- package/examples/gen/js/countrySync.js +0 -31
- package/examples/gen/js/defaultCountryIp.js +0 -11
- package/examples/gen/js/displayNumber.js +0 -4
- package/examples/gen/js/hiddenInput.js +0 -5
- package/examples/gen/js/initPromise.js +0 -9
- package/examples/gen/js/isValidNumber.js +0 -37
- package/examples/gen/js/modifyCountryData.js +0 -11
- package/examples/gen/js/multipleInstances.js +0 -13
- package/examples/gen/js/nationalMode.js +0 -18
- package/examples/gen/js/onlyCountriesEurope.js +0 -8
- package/examples/gen/modify-country-data.html +0 -52
- package/examples/gen/multiple-instances.html +0 -60
- package/examples/gen/national-mode.html +0 -63
- package/examples/gen/only-countries-europe.html +0 -49
- package/examples/js/countrySync.js.ejs +0 -31
- package/examples/js/defaultCountryIp.js.ejs +0 -11
- package/examples/js/displayNumber.js.ejs +0 -4
- package/examples/js/hiddenInput.js.ejs +0 -5
- package/examples/js/initPromise.js.ejs +0 -9
- package/examples/js/isValidNumber.js.ejs +0 -37
- package/examples/js/modifyCountryData.js.ejs +0 -11
- package/examples/js/multipleInstances.js.ejs +0 -13
- package/examples/js/nationalMode.js.ejs +0 -18
- package/examples/js/onlyCountriesEurope.js.ejs +0 -8
- package/examples/js/prism.js +0 -11
- package/examples/partials/countrySync.html +0 -13
- package/examples/partials/defaultCountryIp.html +0 -5
- package/examples/partials/displayNumber.html +0 -1
- package/examples/partials/hiddenInput.html +0 -4
- package/examples/partials/initPromise.html +0 -8
- package/examples/partials/isValidNumber.html +0 -3
- package/examples/partials/multipleInstances.html +0 -3
- package/examples/partials/nationalMode.html +0 -2
- package/examples/partials/simpleInput.html +0 -1
- package/examples/template.html.ejs +0 -43
package/build/js/intlTelInput.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* International Telephone Input v18.
|
|
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")
|
|
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
|
-
//
|
|
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)
|
|
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)
|
|
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)
|
|
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)
|
|
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)
|
|
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)
|
|
313
|
-
|
|
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])
|
|
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)
|
|
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)
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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
|
|
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 (
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
parentClass +=
|
|
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
|
-
|
|
398
|
-
|
|
399
|
-
|
|
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
|
-
|
|
405
|
-
"
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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 (
|
|
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 (
|
|
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 (
|
|
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 (
|
|
460
|
-
var hiddenInputName =
|
|
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)
|
|
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
|
-
|
|
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$
|
|
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)
|
|
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)
|
|
544
|
-
|
|
545
|
-
|
|
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)
|
|
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"))
|
|
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)
|
|
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")
|
|
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
|
|
619
|
-
|
|
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)
|
|
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))
|
|
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)
|
|
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)
|
|
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)
|
|
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")
|
|
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)
|
|
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)
|
|
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
|
|
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 &&
|
|
890
|
-
if (number.charAt(0) !== "1")
|
|
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)
|
|
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)
|
|
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.
|
|
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
|
-
|
|
984
|
-
|
|
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
|
|
1053
|
-
//
|
|
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)
|
|
1076
|
-
|
|
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)
|
|
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)
|
|
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
|
|
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)
|
|
1362
|
+
if (label) {
|
|
1363
|
+
label.removeEventListener("click", this._handleLabelClick);
|
|
1364
|
+
}
|
|
1248
1365
|
}
|
|
1249
1366
|
// unbind hiddenInput listeners
|
|
1250
|
-
if (this.hiddenInput && form)
|
|
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)
|
|
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
|
-
|
|
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 (
|
|
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)
|
|
1478
|
+
if (handleSuccess) {
|
|
1479
|
+
handleSuccess();
|
|
1480
|
+
}
|
|
1359
1481
|
};
|
|
1360
1482
|
script.onerror = function() {
|
|
1361
1483
|
forEachInstance("rejectUtilsScriptPromise");
|
|
1362
|
-
if (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.
|
|
1515
|
+
intlTelInputGlobals.version = "18.1.1";
|
|
1392
1516
|
// convenience wrapper
|
|
1393
1517
|
return function(input, options) {
|
|
1394
1518
|
var iti = new Iti(input, options);
|