", {
203 | "class": "flag-container"
204 | }).insertBefore(this.telInput);
205 | // currently selected flag (displayed to left of input)
206 | var selectedFlag = $("
container
258 | _appendListItems: function(countries, className) {
259 | // we create so many DOM elements, it is faster to build a temp string
260 | // and then add everything to the DOM in one go at the end
261 | var tmp = "";
262 | // for each country
263 | for (var i = 0; i < countries.length; i++) {
264 | var c = countries[i];
265 | // open the list item
266 | tmp += "
";
267 | // add the flag
268 | tmp += "
";
269 | // and the country name and dial code
270 | tmp += "" + c.name + "";
271 | tmp += "+" + c.dialCode + "";
272 | // close the list item
273 | tmp += "
";
274 | }
275 | this.countryList.append(tmp);
276 | },
277 | // set the initial state of the input value and the selected flag by:
278 | // 1. extracting a dial code from the given number
279 | // 2. using explicit initialCountry
280 | // 3. picking the first preferred country
281 | // 4. picking the first country
282 | _setInitialState: function() {
283 | var val = this.telInput.val();
284 | // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the flag, else fall back to the default country
285 | // UPDATE: actually we do want to set the flag for a regionlessNanp in one situation: if we're in nationalMode and there's no initialCountry - otherwise we lose the +1 and we're left with an invalid number
286 | if (this._getDialCode(val) && (!this._isRegionlessNanp(val) || this.options.nationalMode && !this.options.initialCountry)) {
287 | this._updateFlagFromNumber(val);
288 | } else if (this.options.initialCountry !== "auto") {
289 | // see if we should select a flag
290 | if (this.options.initialCountry) {
291 | this._setFlag(this.options.initialCountry.toLowerCase());
292 | } else {
293 | // no dial code and no initialCountry, so default to first in list
294 | this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2;
295 | if (!val) {
296 | this._setFlag(this.defaultCountry);
297 | }
298 | }
299 | // if empty and no nationalMode and no autoHideDialCode then insert the default dial code
300 | if (!val && !this.options.nationalMode && !this.options.autoHideDialCode && !this.options.separateDialCode) {
301 | this.telInput.val("+" + this.selectedCountryData.dialCode);
302 | }
303 | }
304 | // NOTE: if initialCountry is set to auto, that will be handled separately
305 | // format
306 | if (val) {
307 | // this wont be run after _updateDialCode as that's only called if no val
308 | this._updateValFromNumber(val);
309 | }
310 | },
311 | // initialise the main event listeners: input keyup, and click selected flag
312 | _initListeners: function() {
313 | this._initKeyListeners();
314 | if (this.options.autoHideDialCode) {
315 | this._initFocusListeners();
316 | }
317 | if (this.options.allowDropdown) {
318 | this._initDropdownListeners();
319 | }
320 | if (this.hiddenInput) {
321 | this._initHiddenInputListener();
322 | }
323 | },
324 | // update hidden input on form submit
325 | _initHiddenInputListener: function() {
326 | var that = this;
327 | var form = this.telInput.closest("form");
328 | if (form.length) {
329 | form.submit(function() {
330 | that.hiddenInput.val(that.getNumber());
331 | });
332 | }
333 | },
334 | // initialise the dropdown listeners
335 | _initDropdownListeners: function() {
336 | var that = this;
337 | // hack for input nested inside label: clicking the selected-flag to open the dropdown would then automatically trigger a 2nd click on the input which would close it again
338 | var label = this.telInput.closest("label");
339 | if (label.length) {
340 | label.on("click" + this.ns, function(e) {
341 | // if the dropdown is closed, then focus the input, else ignore the click
342 | if (that.countryList.hasClass("hide")) {
343 | that.telInput.focus();
344 | } else {
345 | e.preventDefault();
346 | }
347 | });
348 | }
349 | // toggle country dropdown on click
350 | var selectedFlag = this.selectedFlagInner.parent();
351 | selectedFlag.on("click" + this.ns, function(e) {
352 | // only intercept this event if we're opening the dropdown
353 | // else let it bubble up to the top ("click-off-to-close" listener)
354 | // we cannot just stopPropagation as it may be needed to close another instance
355 | if (that.countryList.hasClass("hide") && !that.telInput.prop("disabled") && !that.telInput.prop("readonly")) {
356 | that._showDropdown();
357 | }
358 | });
359 | // open dropdown list if currently focused
360 | this.flagsContainer.on("keydown" + that.ns, function(e) {
361 | var isDropdownHidden = that.countryList.hasClass("hide");
362 | if (isDropdownHidden && (e.which == keys.UP || e.which == keys.DOWN || e.which == keys.SPACE || e.which == keys.ENTER)) {
363 | // prevent form from being submitted if "ENTER" was pressed
364 | e.preventDefault();
365 | // prevent event from being handled again by document
366 | e.stopPropagation();
367 | that._showDropdown();
368 | }
369 | // allow navigation from dropdown to input on TAB
370 | if (e.which == keys.TAB) {
371 | that._closeDropdown();
372 | }
373 | });
374 | },
375 | // init many requests: utils script / geo ip lookup
376 | _initRequests: function() {
377 | var that = this;
378 | // if the user has specified the path to the utils script, fetch it on window.load, else resolve
379 | if (this.options.utilsScript) {
380 | // if the plugin is being initialised after the window.load event has already been fired
381 | if ($.fn[pluginName].windowLoaded) {
382 | $.fn[pluginName].loadUtils(this.options.utilsScript, this.utilsScriptDeferred);
383 | } else {
384 | // wait until the load event so we don't block any other requests e.g. the flags image
385 | $(window).on("load", function() {
386 | $.fn[pluginName].loadUtils(that.options.utilsScript, that.utilsScriptDeferred);
387 | });
388 | }
389 | } else {
390 | this.utilsScriptDeferred.resolve();
391 | }
392 | if (this.options.initialCountry === "auto") {
393 | this._loadAutoCountry();
394 | } else {
395 | this.autoCountryDeferred.resolve();
396 | }
397 | },
398 | // perform the geo ip lookup
399 | _loadAutoCountry: function() {
400 | var that = this;
401 | // 3 options:
402 | // 1) already loaded (we're done)
403 | // 2) not already started loading (start)
404 | // 3) already started loading (do nothing - just wait for loading callback to fire)
405 | if ($.fn[pluginName].autoCountry) {
406 | this.handleAutoCountry();
407 | } else if (!$.fn[pluginName].startedLoadingAutoCountry) {
408 | // don't do this twice!
409 | $.fn[pluginName].startedLoadingAutoCountry = true;
410 | if (typeof this.options.geoIpLookup === "function") {
411 | this.options.geoIpLookup(function(countryCode) {
412 | $.fn[pluginName].autoCountry = countryCode.toLowerCase();
413 | // tell all instances the auto country is ready
414 | // TODO: this should just be the current instances
415 | // UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight away (e.g. if they have already done the geo ip lookup somewhere else). Using setTimeout means that the current thread of execution will finish before executing this, which allows the plugin to finish initialising.
416 | setTimeout(function() {
417 | $(".intl-tel-input input").intlTelInput("handleAutoCountry");
418 | });
419 | });
420 | }
421 | }
422 | },
423 | // initialize any key listeners
424 | _initKeyListeners: function() {
425 | var that = this;
426 | // update flag on keyup
427 | // (keep this listener separate otherwise the setTimeout breaks all the tests)
428 | this.telInput.on("keyup" + this.ns, function() {
429 | if (that._updateFlagFromNumber(that.telInput.val())) {
430 | that._triggerCountryChange();
431 | }
432 | });
433 | // update flag on cut/paste events (now supported in all major browsers)
434 | this.telInput.on("cut" + this.ns + " paste" + this.ns, function() {
435 | // hack because "paste" event is fired before input is updated
436 | setTimeout(function() {
437 | if (that._updateFlagFromNumber(that.telInput.val())) {
438 | that._triggerCountryChange();
439 | }
440 | });
441 | });
442 | },
443 | // adhere to the input's maxlength attr
444 | _cap: function(number) {
445 | var max = this.telInput.attr("maxlength");
446 | return max && number.length > max ? number.substr(0, max) : number;
447 | },
448 | // listen for mousedown, focus and blur
449 | _initFocusListeners: function() {
450 | var that = this;
451 | // mousedown decides where the cursor goes, so if we're focusing we must preventDefault as we'll be inserting the dial code, and we want the cursor to be at the end no matter where they click
452 | this.telInput.on("mousedown" + this.ns, function(e) {
453 | if (!that.telInput.is(":focus") && !that.telInput.val()) {
454 | e.preventDefault();
455 | // but this also cancels the focus, so we must trigger that manually
456 | that.telInput.focus();
457 | }
458 | });
459 | // on focus: if empty, insert the dial code for the currently selected flag
460 | this.telInput.on("focus" + this.ns, function(e) {
461 | if (!that.telInput.val() && !that.telInput.prop("readonly") && that.selectedCountryData.dialCode) {
462 | // insert the dial code
463 | that.telInput.val("+" + that.selectedCountryData.dialCode);
464 | // after auto-inserting a dial code, if the first key they hit is '+' then assume they are entering a new number, so remove the dial code. use keypress instead of keydown because keydown gets triggered for the shift key (required to hit the + key), and instead of keyup because that shows the new '+' before removing the old one
465 | that.telInput.one("keypress.plus" + that.ns, function(e) {
466 | if (e.which == keys.PLUS) {
467 | that.telInput.val("");
468 | }
469 | });
470 | // after tabbing in, make sure the cursor is at the end we must use setTimeout to get outside of the focus handler as it seems the selection happens after that
471 | setTimeout(function() {
472 | var input = that.telInput[0];
473 | if (that.isGoodBrowser) {
474 | var len = that.telInput.val().length;
475 | input.setSelectionRange(len, len);
476 | }
477 | });
478 | }
479 | });
480 | // on blur or form submit: if just a dial code then remove it
481 | var form = this.telInput.prop("form");
482 | if (form) {
483 | $(form).on("submit" + this.ns, function() {
484 | that._removeEmptyDialCode();
485 | });
486 | }
487 | this.telInput.on("blur" + this.ns, function() {
488 | that._removeEmptyDialCode();
489 | });
490 | },
491 | _removeEmptyDialCode: function() {
492 | var value = this.telInput.val(), startsPlus = value.charAt(0) == "+";
493 | if (startsPlus) {
494 | var numeric = this._getNumeric(value);
495 | // if just a plus, or if just a dial code
496 | if (!numeric || this.selectedCountryData.dialCode == numeric) {
497 | this.telInput.val("");
498 | }
499 | }
500 | // remove the keypress listener we added on focus
501 | this.telInput.off("keypress.plus" + this.ns);
502 | },
503 | // extract the numeric digits from the given string
504 | _getNumeric: function(s) {
505 | return s.replace(/\D/g, "");
506 | },
507 | // show the dropdown
508 | _showDropdown: function() {
509 | this._setDropdownPosition();
510 | // update highlighting and scroll to active list item
511 | var activeListItem = this.countryList.children(".active");
512 | if (activeListItem.length) {
513 | this._highlightListItem(activeListItem);
514 | this._scrollTo(activeListItem);
515 | }
516 | // bind all the dropdown-related listeners: mouseover, click, click-off, keydown
517 | this._bindDropdownListeners();
518 | // update the arrow
519 | this.selectedFlagInner.children(".iti-arrow").addClass("up");
520 | this.telInput.trigger("open:countrydropdown");
521 | },
522 | // decide where to position dropdown (depends on position within viewport, and scroll)
523 | _setDropdownPosition: function() {
524 | var that = this;
525 | if (this.options.dropdownContainer) {
526 | this.dropdown.appendTo(this.options.dropdownContainer);
527 | }
528 | // show the menu and grab the dropdown height
529 | this.dropdownHeight = this.countryList.removeClass("hide").outerHeight();
530 | if (!this.isMobile) {
531 | var pos = this.telInput.offset(), inputTop = pos.top, windowTop = $(window).scrollTop(), // dropdownFitsBelow = (dropdownBottom < windowBottom)
532 | dropdownFitsBelow = inputTop + this.telInput.outerHeight() + this.dropdownHeight < windowTop + $(window).height(), dropdownFitsAbove = inputTop - this.dropdownHeight > windowTop;
533 | // by default, the dropdown will be below the input. If we want to position it above the input, we add the dropup class.
534 | this.countryList.toggleClass("dropup", !dropdownFitsBelow && dropdownFitsAbove);
535 | // if dropdownContainer is enabled, calculate postion
536 | if (this.options.dropdownContainer) {
537 | // by default the dropdown will be directly over the input because it's not in the flow. If we want to position it below, we need to add some extra top value.
538 | var extraTop = !dropdownFitsBelow && dropdownFitsAbove ? 0 : this.telInput.innerHeight();
539 | // calculate placement
540 | this.dropdown.css({
541 | top: inputTop + extraTop,
542 | left: pos.left
543 | });
544 | // close menu on window scroll
545 | $(window).on("scroll" + this.ns, function() {
546 | that._closeDropdown();
547 | });
548 | }
549 | }
550 | },
551 | // we only bind dropdown listeners when the dropdown is open
552 | _bindDropdownListeners: function() {
553 | var that = this;
554 | // when mouse over a list item, just highlight that one
555 | // we add the class "highlight", so if they hit "enter" we know which one to select
556 | this.countryList.on("mouseover" + this.ns, ".country", function(e) {
557 | that._highlightListItem($(this));
558 | });
559 | // listen for country selection
560 | this.countryList.on("click" + this.ns, ".country", function(e) {
561 | that._selectListItem($(this));
562 | });
563 | // click off to close
564 | // (except when this initial opening click is bubbling up)
565 | // we cannot just stopPropagation as it may be needed to close another instance
566 | var isOpening = true;
567 | $("html").on("click" + this.ns, function(e) {
568 | if (!isOpening) {
569 | that._closeDropdown();
570 | }
571 | isOpening = false;
572 | });
573 | // listen for up/down scrolling, enter to select, or letters to jump to country name.
574 | // use keydown as keypress doesn't fire for non-char keys and we want to catch if they
575 | // just hit down and hold it to scroll down (no keyup event).
576 | // listen on the document because that's where key events are triggered if no input has focus
577 | var query = "", queryTimer = null;
578 | $(document).on("keydown" + this.ns, function(e) {
579 | // prevent down key from scrolling the whole page,
580 | // and enter key from submitting a form etc
581 | e.preventDefault();
582 | if (e.which == keys.UP || e.which == keys.DOWN) {
583 | // up and down to navigate
584 | that._handleUpDownKey(e.which);
585 | } else if (e.which == keys.ENTER) {
586 | // enter to select
587 | that._handleEnterKey();
588 | } else if (e.which == keys.ESC) {
589 | // esc to close
590 | that._closeDropdown();
591 | } else if (e.which >= keys.A && e.which <= keys.Z || e.which == keys.SPACE) {
592 | // upper case letters (note: keyup/keydown only return upper case letters)
593 | // jump to countries that start with the query string
594 | if (queryTimer) {
595 | clearTimeout(queryTimer);
596 | }
597 | query += String.fromCharCode(e.which);
598 | that._searchForCountry(query);
599 | // if the timer hits 1 second, reset the query
600 | queryTimer = setTimeout(function() {
601 | query = "";
602 | }, 1e3);
603 | }
604 | });
605 | },
606 | // highlight the next/prev item in the list (and ensure it is visible)
607 | _handleUpDownKey: function(key) {
608 | var current = this.countryList.children(".highlight").first();
609 | var next = key == keys.UP ? current.prev() : current.next();
610 | if (next.length) {
611 | // skip the divider
612 | if (next.hasClass("divider")) {
613 | next = key == keys.UP ? next.prev() : next.next();
614 | }
615 | this._highlightListItem(next);
616 | this._scrollTo(next);
617 | }
618 | },
619 | // select the currently highlighted item
620 | _handleEnterKey: function() {
621 | var currentCountry = this.countryList.children(".highlight").first();
622 | if (currentCountry.length) {
623 | this._selectListItem(currentCountry);
624 | }
625 | },
626 | // find the first list item whose name starts with the query string
627 | _searchForCountry: function(query) {
628 | for (var i = 0; i < this.countries.length; i++) {
629 | if (this._startsWith(this.countries[i].name, query)) {
630 | var listItem = this.countryList.children("[data-country-code=" + this.countries[i].iso2 + "]").not(".preferred");
631 | // update highlighting and scroll
632 | this._highlightListItem(listItem);
633 | this._scrollTo(listItem, true);
634 | break;
635 | }
636 | }
637 | },
638 | // check if (uppercase) string a starts with string b
639 | _startsWith: function(a, b) {
640 | return a.substr(0, b.length).toUpperCase() == b;
641 | },
642 | // update the input's value to the given val (format first if possible)
643 | // NOTE: this is called from _setInitialState, handleUtils and setNumber
644 | _updateValFromNumber: function(number) {
645 | if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) {
646 | var format = !this.options.separateDialCode && (this.options.nationalMode || number.charAt(0) != "+") ? intlTelInputUtils.numberFormat.NATIONAL : intlTelInputUtils.numberFormat.INTERNATIONAL;
647 | number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format);
648 | }
649 | number = this._beforeSetNumber(number);
650 | this.telInput.val(number);
651 | },
652 | // check if need to select a new flag based on the given number
653 | // Note: called from _setInitialState, keyup handler, setNumber
654 | _updateFlagFromNumber: function(number) {
655 | // if we're in nationalMode and we already have US/Canada selected, make sure the number starts with a +1 so _getDialCode will be able to extract the area code
656 | // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag from the number), that means we're initialising the plugin with a number that already has a dial code, so fine to ignore this bit
657 | if (number && this.options.nationalMode && this.selectedCountryData.dialCode == "1" && number.charAt(0) != "+") {
658 | if (number.charAt(0) != "1") {
659 | number = "1" + number;
660 | }
661 | number = "+" + number;
662 | }
663 | // try and extract valid dial code from input
664 | var dialCode = this._getDialCode(number), countryCode = null, numeric = this._getNumeric(number);
665 | if (dialCode) {
666 | // check if one of the matching countries is already selected
667 | var countryCodes = this.countryCodes[this._getNumeric(dialCode)], alreadySelected = $.inArray(this.selectedCountryData.iso2, countryCodes) > -1, // check if the given number contains a NANP area code i.e. the only dialCode that could be extracted was +1 (instead of say +1204) and the actual number's length is >=4
668 | isNanpAreaCode = dialCode == "+1" && numeric.length >= 4, nanpSelected = this.selectedCountryData.dialCode == "1";
669 | // only update the flag if:
670 | // A) NOT (we currently have a NANP flag selected, and the number is a regionlessNanp)
671 | // AND
672 | // B) either a matching country is not already selected OR the number contains a NANP area code (ensure the flag is set to the first matching country)
673 | if (!(nanpSelected && this._isRegionlessNanp(numeric)) && (!alreadySelected || isNanpAreaCode)) {
674 | // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first non-empty index
675 | for (var j = 0; j < countryCodes.length; j++) {
676 | if (countryCodes[j]) {
677 | countryCode = countryCodes[j];
678 | break;
679 | }
680 | }
681 | }
682 | } else if (number.charAt(0) == "+" && numeric.length) {
683 | // invalid dial code, so empty
684 | // Note: use getNumeric here because the number has not been formatted yet, so could contain bad chars
685 | countryCode = "";
686 | } else if (!number || number == "+") {
687 | // empty, or just a plus, so default
688 | countryCode = this.defaultCountry;
689 | }
690 | if (countryCode !== null) {
691 | return this._setFlag(countryCode);
692 | }
693 | return false;
694 | },
695 | // check if the given number is a regionless NANP number (expects the number to contain an international dial code)
696 | _isRegionlessNanp: function(number) {
697 | var numeric = this._getNumeric(number);
698 | if (numeric.charAt(0) == "1") {
699 | var areaCode = numeric.substr(1, 3);
700 | return $.inArray(areaCode, regionlessNanpNumbers) > -1;
701 | }
702 | return false;
703 | },
704 | // remove highlighting from other list items and highlight the given item
705 | _highlightListItem: function(listItem) {
706 | this.countryListItems.removeClass("highlight");
707 | listItem.addClass("highlight");
708 | },
709 | // find the country data for the given country code
710 | // the ignoreOnlyCountriesOption is only used during init() while parsing the onlyCountries array
711 | _getCountryData: function(countryCode, ignoreOnlyCountriesOption, allowFail) {
712 | var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries;
713 | for (var i = 0; i < countryList.length; i++) {
714 | if (countryList[i].iso2 == countryCode) {
715 | return countryList[i];
716 | }
717 | }
718 | if (allowFail) {
719 | return null;
720 | } else {
721 | throw new Error("No country data for '" + countryCode + "'");
722 | }
723 | },
724 | // select the given flag, update the placeholder and the active list item
725 | // Note: called from _setInitialState, _updateFlagFromNumber, _selectListItem, setCountry
726 | _setFlag: function(countryCode) {
727 | var prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {};
728 | // do this first as it will throw an error and stop if countryCode is invalid
729 | this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {};
730 | // update the defaultCountry - we only need the iso2 from now on, so just store that
731 | if (this.selectedCountryData.iso2) {
732 | this.defaultCountry = this.selectedCountryData.iso2;
733 | }
734 | this.selectedFlagInner.attr("class", "iti-flag " + countryCode);
735 | // update the selected country's title attribute
736 | var title = countryCode ? this.selectedCountryData.name + ": +" + this.selectedCountryData.dialCode : "Unknown";
737 | this.selectedFlagInner.parent().attr("title", title);
738 | if (this.options.separateDialCode) {
739 | var dialCode = this.selectedCountryData.dialCode ? "+" + this.selectedCountryData.dialCode : "", parent = this.telInput.parent();
740 | if (prevCountry.dialCode) {
741 | parent.removeClass("iti-sdc-" + (prevCountry.dialCode.length + 1));
742 | }
743 | if (dialCode) {
744 | parent.addClass("iti-sdc-" + dialCode.length);
745 | }
746 | this.selectedDialCode.text(dialCode);
747 | }
748 | // and the input's placeholder
749 | this._updatePlaceholder();
750 | // update the active list item
751 | this.countryListItems.removeClass("active");
752 | if (countryCode) {
753 | this.countryListItems.find(".iti-flag." + countryCode).first().closest(".country").addClass("active");
754 | }
755 | // return if the flag has changed or not
756 | return prevCountry.iso2 !== countryCode;
757 | },
758 | // update the input placeholder to an example number from the currently selected country
759 | _updatePlaceholder: function() {
760 | var shouldSetPlaceholder = this.options.autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && (this.options.autoPlaceholder === true || this.options.autoPlaceholder === "polite");
761 | if (window.intlTelInputUtils && shouldSetPlaceholder) {
762 | var numberType = intlTelInputUtils.numberType[this.options.placeholderNumberType], placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, this.options.nationalMode, numberType) : "";
763 | placeholder = this._beforeSetNumber(placeholder);
764 | if (typeof this.options.customPlaceholder === "function") {
765 | placeholder = this.options.customPlaceholder(placeholder, this.selectedCountryData);
766 | }
767 | this.telInput.attr("placeholder", placeholder);
768 | }
769 | },
770 | // called when the user selects a list item from the dropdown
771 | _selectListItem: function(listItem) {
772 | // update selected flag and active list item
773 | var flagChanged = this._setFlag(listItem.attr("data-country-code"));
774 | this._closeDropdown();
775 | this._updateDialCode(listItem.attr("data-dial-code"), true);
776 | // focus the input
777 | this.telInput.focus();
778 | // put cursor at end - this fix is required for FF and IE11 (with nationalMode=false i.e. auto inserting dial code), who try to put the cursor at the beginning the first time
779 | if (this.isGoodBrowser) {
780 | var len = this.telInput.val().length;
781 | this.telInput[0].setSelectionRange(len, len);
782 | }
783 | if (flagChanged) {
784 | this._triggerCountryChange();
785 | }
786 | },
787 | // close the dropdown and unbind any listeners
788 | _closeDropdown: function() {
789 | this.countryList.addClass("hide");
790 | // update the arrow
791 | this.selectedFlagInner.children(".iti-arrow").removeClass("up");
792 | // unbind key events
793 | $(document).off(this.ns);
794 | // unbind click-off-to-close
795 | $("html").off(this.ns);
796 | // unbind hover and click listeners
797 | this.countryList.off(this.ns);
798 | // remove menu from container
799 | if (this.options.dropdownContainer) {
800 | if (!this.isMobile) {
801 | $(window).off("scroll" + this.ns);
802 | }
803 | this.dropdown.detach();
804 | }
805 | this.telInput.trigger("close:countrydropdown");
806 | },
807 | // check if an element is visible within it's container, else scroll until it is
808 | _scrollTo: function(element, middle) {
809 | var container = this.countryList, containerHeight = container.height(), containerTop = container.offset().top, containerBottom = containerTop + containerHeight, elementHeight = element.outerHeight(), elementTop = element.offset().top, elementBottom = elementTop + elementHeight, newScrollTop = elementTop - containerTop + container.scrollTop(), middleOffset = containerHeight / 2 - elementHeight / 2;
810 | if (elementTop < containerTop) {
811 | // scroll up
812 | if (middle) {
813 | newScrollTop -= middleOffset;
814 | }
815 | container.scrollTop(newScrollTop);
816 | } else if (elementBottom > containerBottom) {
817 | // scroll down
818 | if (middle) {
819 | newScrollTop += middleOffset;
820 | }
821 | var heightDifference = containerHeight - elementHeight;
822 | container.scrollTop(newScrollTop - heightDifference);
823 | }
824 | },
825 | // replace any existing dial code with the new one
826 | // Note: called from _selectListItem and setCountry
827 | _updateDialCode: function(newDialCode, hasSelectedListItem) {
828 | var inputVal = this.telInput.val(), newNumber;
829 | // save having to pass this every time
830 | newDialCode = "+" + newDialCode;
831 | if (inputVal.charAt(0) == "+") {
832 | // there's a plus so we're dealing with a replacement (doesn't matter if nationalMode or not)
833 | var prevDialCode = this._getDialCode(inputVal);
834 | if (prevDialCode) {
835 | // current number contains a valid dial code, so replace it
836 | newNumber = inputVal.replace(prevDialCode, newDialCode);
837 | } else {
838 | // current number contains an invalid dial code, so ditch it
839 | // (no way to determine where the invalid dial code ends and the rest of the number begins)
840 | newNumber = newDialCode;
841 | }
842 | } else if (this.options.nationalMode || this.options.separateDialCode) {
843 | // don't do anything
844 | return;
845 | } else {
846 | // nationalMode is disabled
847 | if (inputVal) {
848 | // there is an existing value with no dial code: prefix the new dial code
849 | newNumber = newDialCode + inputVal;
850 | } else if (hasSelectedListItem || !this.options.autoHideDialCode) {
851 | // no existing value and either they've just selected a list item, or autoHideDialCode is disabled: insert new dial code
852 | newNumber = newDialCode;
853 | } else {
854 | return;
855 | }
856 | }
857 | this.telInput.val(newNumber);
858 | },
859 | // try and extract a valid international dial code from a full telephone number
860 | // Note: returns the raw string inc plus character and any whitespace/dots etc
861 | _getDialCode: function(number) {
862 | var dialCode = "";
863 | // only interested in international numbers (starting with a plus)
864 | if (number.charAt(0) == "+") {
865 | var numericChars = "";
866 | // iterate over chars
867 | for (var i = 0; i < number.length; i++) {
868 | var c = number.charAt(i);
869 | // if char is number
870 | if ($.isNumeric(c)) {
871 | numericChars += c;
872 | // if current numericChars make a valid dial code
873 | if (this.countryCodes[numericChars]) {
874 | // store the actual raw string (useful for matching later)
875 | dialCode = number.substr(0, i + 1);
876 | }
877 | // longest dial code is 4 chars
878 | if (numericChars.length == 4) {
879 | break;
880 | }
881 | }
882 | }
883 | }
884 | return dialCode;
885 | },
886 | // get the input val, adding the dial code if separateDialCode is enabled
887 | _getFullNumber: function() {
888 | var val = $.trim(this.telInput.val()), dialCode = this.selectedCountryData.dialCode, prefix, numericVal = this._getNumeric(val), // normalized means ensure starts with a 1, so we can match against the full dial code
889 | normalizedVal = numericVal.charAt(0) == "1" ? numericVal : "1" + numericVal;
890 | if (this.options.separateDialCode) {
891 | prefix = "+" + dialCode;
892 | } else if (val.charAt(0) != "+" && val.charAt(0) != "1" && dialCode && dialCode.charAt(0) == "1" && dialCode.length == 4 && dialCode != normalizedVal.substr(0, 4)) {
893 | // if the user has entered a national NANP number, then ensure it includes the full dial code / area code
894 | prefix = dialCode.substr(1);
895 | } else {
896 | prefix = "";
897 | }
898 | return prefix + val;
899 | },
900 | // remove the dial code if separateDialCode is enabled
901 | _beforeSetNumber: function(number) {
902 | if (this.options.separateDialCode) {
903 | var dialCode = this._getDialCode(number);
904 | if (dialCode) {
905 | // US dialCode is "+1", which is what we want
906 | // CA dialCode is "+1 123", which is wrong - should be "+1" (as it has multiple area codes)
907 | // AS dialCode is "+1 684", which is what we want
908 | // Solution: if the country has area codes, then revert to just the dial code
909 | if (this.selectedCountryData.areaCodes !== null) {
910 | dialCode = "+" + this.selectedCountryData.dialCode;
911 | }
912 | // a lot of numbers will have a space separating the dial code and the main number, and some NANP numbers will have a hyphen e.g. +1 684-733-1234 - in both cases we want to get rid of it
913 | // NOTE: don't just trim all non-numerics as may want to preserve an open parenthesis etc
914 | var start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
915 | number = number.substr(start);
916 | }
917 | }
918 | return this._cap(number);
919 | },
920 | // trigger the 'countrychange' event
921 | _triggerCountryChange: function() {
922 | this.telInput.trigger("countrychange", this.selectedCountryData);
923 | },
924 | /**************************
925 | * SECRET PUBLIC METHODS
926 | **************************/
927 | // this is called when the geoip call returns
928 | handleAutoCountry: function() {
929 | if (this.options.initialCountry === "auto") {
930 | // we must set this even if there is an initial val in the input: in case the initial val is invalid and they delete it - they should see their auto country
931 | this.defaultCountry = $.fn[pluginName].autoCountry;
932 | // if there's no initial value in the input, then update the flag
933 | if (!this.telInput.val()) {
934 | this.setCountry(this.defaultCountry);
935 | }
936 | this.autoCountryDeferred.resolve();
937 | }
938 | },
939 | // this is called when the utils request completes
940 | handleUtils: function() {
941 | // if the request was successful
942 | if (window.intlTelInputUtils) {
943 | // if there's an initial value in the input, then format it
944 | if (this.telInput.val()) {
945 | this._updateValFromNumber(this.telInput.val());
946 | }
947 | this._updatePlaceholder();
948 | }
949 | this.utilsScriptDeferred.resolve();
950 | },
951 | /********************
952 | * PUBLIC METHODS
953 | ********************/
954 | // remove plugin
955 | destroy: function() {
956 | if (this.allowDropdown) {
957 | // make sure the dropdown is closed (and unbind listeners)
958 | this._closeDropdown();
959 | // click event to open dropdown
960 | this.selectedFlagInner.parent().off(this.ns);
961 | // label click hack
962 | this.telInput.closest("label").off(this.ns);
963 | }
964 | // unbind submit event handler on form
965 | if (this.options.autoHideDialCode) {
966 | var form = this.telInput.prop("form");
967 | if (form) {
968 | $(form).off(this.ns);
969 | }
970 | }
971 | // unbind all events: key events, and focus/blur events if autoHideDialCode=true
972 | this.telInput.off(this.ns);
973 | // remove markup (but leave the original input)
974 | var container = this.telInput.parent();
975 | container.before(this.telInput).remove();
976 | },
977 | // get the extension from the current number
978 | getExtension: function() {
979 | if (window.intlTelInputUtils) {
980 | return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2);
981 | }
982 | return "";
983 | },
984 | // format the number to the given format
985 | getNumber: function(format) {
986 | if (window.intlTelInputUtils) {
987 | return intlTelInputUtils.formatNumber(this._getFullNumber(), this.selectedCountryData.iso2, format);
988 | }
989 | return "";
990 | },
991 | // get the type of the entered number e.g. landline/mobile
992 | getNumberType: function() {
993 | if (window.intlTelInputUtils) {
994 | return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2);
995 | }
996 | return -99;
997 | },
998 | // get the country data for the currently selected flag
999 | getSelectedCountryData: function() {
1000 | return this.selectedCountryData;
1001 | },
1002 | // get the validation error
1003 | getValidationError: function() {
1004 | if (window.intlTelInputUtils) {
1005 | return intlTelInputUtils.getValidationError(this._getFullNumber(), this.selectedCountryData.iso2);
1006 | }
1007 | return -99;
1008 | },
1009 | // validate the input val - assumes the global function isValidNumber (from utilsScript)
1010 | isValidNumber: function() {
1011 | var val = $.trim(this._getFullNumber()), countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : "";
1012 | return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null;
1013 | },
1014 | // update the selected flag, and update the input val accordingly
1015 | setCountry: function(countryCode) {
1016 | countryCode = countryCode.toLowerCase();
1017 | // check if already selected
1018 | if (!this.selectedFlagInner.hasClass(countryCode)) {
1019 | this._setFlag(countryCode);
1020 | this._updateDialCode(this.selectedCountryData.dialCode, false);
1021 | this._triggerCountryChange();
1022 | }
1023 | },
1024 | // set the input value and update the flag
1025 | setNumber: function(number) {
1026 | // we must update the flag first, which updates this.selectedCountryData, which is used for formatting the number before displaying it
1027 | var flagChanged = this._updateFlagFromNumber(number);
1028 | this._updateValFromNumber(number);
1029 | if (flagChanged) {
1030 | this._triggerCountryChange();
1031 | }
1032 | },
1033 | // set the placeholder number typ
1034 | setPlaceholderNumberType: function(type) {
1035 | this.options.placeholderNumberType = type;
1036 | this._updatePlaceholder();
1037 | }
1038 | };
1039 | // using https://github.com/jquery-boilerplate/jquery-boilerplate/wiki/Extending-jQuery-Boilerplate
1040 | // (adapted to allow public functions)
1041 | $.fn[pluginName] = function(options) {
1042 | var args = arguments;
1043 | // Is the first parameter an object (options), or was omitted,
1044 | // instantiate a new instance of the plugin.
1045 | if (options === undefined || typeof options === "object") {
1046 | // collect all of the deferred objects for all instances created with this selector
1047 | var deferreds = [];
1048 | this.each(function() {
1049 | if (!$.data(this, "plugin_" + pluginName)) {
1050 | var instance = new Plugin(this, options);
1051 | var instanceDeferreds = instance._init();
1052 | // we now have 2 deffereds: 1 for auto country, 1 for utils script
1053 | deferreds.push(instanceDeferreds[0]);
1054 | deferreds.push(instanceDeferreds[1]);
1055 | $.data(this, "plugin_" + pluginName, instance);
1056 | }
1057 | });
1058 | // return the promise from the "master" deferred object that tracks all the others
1059 | return $.when.apply(null, deferreds);
1060 | } else if (typeof options === "string" && options[0] !== "_") {
1061 | // If the first parameter is a string and it doesn't start
1062 | // with an underscore or "contains" the `init`-function,
1063 | // treat this as a call to a public method.
1064 | // Cache the method call to make it possible to return a value
1065 | var returns;
1066 | this.each(function() {
1067 | var instance = $.data(this, "plugin_" + pluginName);
1068 | // Tests that there's already a plugin-instance
1069 | // and checks that the requested public method exists
1070 | if (instance instanceof Plugin && typeof instance[options] === "function") {
1071 | // Call the method of our plugin instance,
1072 | // and pass it the supplied arguments.
1073 | returns = instance[options].apply(instance, Array.prototype.slice.call(args, 1));
1074 | }
1075 | // Allow instances to be destroyed via the 'destroy' method
1076 | if (options === "destroy") {
1077 | $.data(this, "plugin_" + pluginName, null);
1078 | }
1079 | });
1080 | // If the earlier cached method gives a value back return the value,
1081 | // otherwise return this to preserve chainability.
1082 | return returns !== undefined ? returns : this;
1083 | }
1084 | };
1085 | /********************
1086 | * STATIC METHODS
1087 | ********************/
1088 | // get the country data object
1089 | $.fn[pluginName].getCountryData = function() {
1090 | return allCountries;
1091 | };
1092 | // load the utils script
1093 | $.fn[pluginName].loadUtils = function(path, utilsScriptDeferred) {
1094 | if (!$.fn[pluginName].loadedUtilsScript) {
1095 | // don't do this twice! (dont just check if window.intlTelInputUtils exists as if init plugin multiple times in quick succession, it may not have finished loading yet)
1096 | $.fn[pluginName].loadedUtilsScript = true;
1097 | // dont use $.getScript as it prevents caching
1098 | $.ajax({
1099 | type: "GET",
1100 | url: path,
1101 | complete: function() {
1102 | // tell all instances that the utils request is complete
1103 | $(".intl-tel-input input").intlTelInput("handleUtils");
1104 | },
1105 | dataType: "script",
1106 | cache: true
1107 | });
1108 | } else if (utilsScriptDeferred) {
1109 | utilsScriptDeferred.resolve();
1110 | }
1111 | };
1112 | // default options
1113 | $.fn[pluginName].defaults = defaults;
1114 | // version
1115 | $.fn[pluginName].version = "12.1.0";
1116 | // Array of country objects for the flag dropdown.
1117 | // Here is the criteria for the plugin to support a given country/territory
1118 | // - It has an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
1119 | // - It has it's own country calling code (it is not a sub-region of another country): https://en.wikipedia.org/wiki/List_of_country_calling_codes
1120 | // - It has a flag in the region-flags project: https://github.com/behdad/region-flags/tree/gh-pages/png
1121 | // - It is supported by libphonenumber (it must be listed on this page): https://github.com/googlei18n/libphonenumber/blob/master/resources/ShortNumberMetadata.xml
1122 | // Each country array has the following information:
1123 | // [
1124 | // Country name,
1125 | // iso2 code,
1126 | // International dial code,
1127 | // Order (if >1 country with same dial code),
1128 | // Area codes
1129 | // ]
1130 | var allCountries = [ [ "Afghanistan (افغانستان)", "af", "93" ], [ "Albania (Shqipëri)", "al", "355" ], [ "Algeria (الجزائر)", "dz", "213" ], [ "American Samoa", "as", "1684" ], [ "Andorra", "ad", "376" ], [ "Angola", "ao", "244" ], [ "Anguilla", "ai", "1264" ], [ "Antigua and Barbuda", "ag", "1268" ], [ "Argentina", "ar", "54" ], [ "Armenia (Հայաստան)", "am", "374" ], [ "Aruba", "aw", "297" ], [ "Australia", "au", "61", 0 ], [ "Austria (Österreich)", "at", "43" ], [ "Azerbaijan (Azərbaycan)", "az", "994" ], [ "Bahamas", "bs", "1242" ], [ "Bahrain (البحرين)", "bh", "973" ], [ "Bangladesh (বাংলাদেশ)", "bd", "880" ], [ "Barbados", "bb", "1246" ], [ "Belarus (Беларусь)", "by", "375" ], [ "Belgium (België)", "be", "32" ], [ "Belize", "bz", "501" ], [ "Benin (Bénin)", "bj", "229" ], [ "Bermuda", "bm", "1441" ], [ "Bhutan (འབྲུག)", "bt", "975" ], [ "Bolivia", "bo", "591" ], [ "Bosnia and Herzegovina (Босна и Херцеговина)", "ba", "387" ], [ "Botswana", "bw", "267" ], [ "Brazil (Brasil)", "br", "55" ], [ "British Indian Ocean Territory", "io", "246" ], [ "British Virgin Islands", "vg", "1284" ], [ "Brunei", "bn", "673" ], [ "Bulgaria (България)", "bg", "359" ], [ "Burkina Faso", "bf", "226" ], [ "Burundi (Uburundi)", "bi", "257" ], [ "Cambodia (កម្ពុជា)", "kh", "855" ], [ "Cameroon (Cameroun)", "cm", "237" ], [ "Canada", "ca", "1", 1, [ "204", "226", "236", "249", "250", "289", "306", "343", "365", "387", "403", "416", "418", "431", "437", "438", "450", "506", "514", "519", "548", "579", "581", "587", "604", "613", "639", "647", "672", "705", "709", "742", "778", "780", "782", "807", "819", "825", "867", "873", "902", "905" ] ], [ "Cape Verde (Kabu Verdi)", "cv", "238" ], [ "Caribbean Netherlands", "bq", "599", 1 ], [ "Cayman Islands", "ky", "1345" ], [ "Central African Republic (République centrafricaine)", "cf", "236" ], [ "Chad (Tchad)", "td", "235" ], [ "Chile", "cl", "56" ], [ "China (中国)", "cn", "86" ], [ "Christmas Island", "cx", "61", 2 ], [ "Cocos (Keeling) Islands", "cc", "61", 1 ], [ "Colombia", "co", "57" ], [ "Comoros (جزر القمر)", "km", "269" ], [ "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)", "cd", "243" ], [ "Congo (Republic) (Congo-Brazzaville)", "cg", "242" ], [ "Cook Islands", "ck", "682" ], [ "Costa Rica", "cr", "506" ], [ "Côte d’Ivoire", "ci", "225" ], [ "Croatia (Hrvatska)", "hr", "385" ], [ "Cuba", "cu", "53" ], [ "Curaçao", "cw", "599", 0 ], [ "Cyprus (Κύπρος)", "cy", "357" ], [ "Czech Republic (Česká republika)", "cz", "420" ], [ "Denmark (Danmark)", "dk", "45" ], [ "Djibouti", "dj", "253" ], [ "Dominica", "dm", "1767" ], [ "Dominican Republic (República Dominicana)", "do", "1", 2, [ "809", "829", "849" ] ], [ "Ecuador", "ec", "593" ], [ "Egypt (مصر)", "eg", "20" ], [ "El Salvador", "sv", "503" ], [ "Equatorial Guinea (Guinea Ecuatorial)", "gq", "240" ], [ "Eritrea", "er", "291" ], [ "Estonia (Eesti)", "ee", "372" ], [ "Ethiopia", "et", "251" ], [ "Falkland Islands (Islas Malvinas)", "fk", "500" ], [ "Faroe Islands (Føroyar)", "fo", "298" ], [ "Fiji", "fj", "679" ], [ "Finland (Suomi)", "fi", "358", 0 ], [ "France", "fr", "33" ], [ "French Guiana (Guyane française)", "gf", "594" ], [ "French Polynesia (Polynésie française)", "pf", "689" ], [ "Gabon", "ga", "241" ], [ "Gambia", "gm", "220" ], [ "Georgia (საქართველო)", "ge", "995" ], [ "Germany (Deutschland)", "de", "49" ], [ "Ghana (Gaana)", "gh", "233" ], [ "Gibraltar", "gi", "350" ], [ "Greece (Ελλάδα)", "gr", "30" ], [ "Greenland (Kalaallit Nunaat)", "gl", "299" ], [ "Grenada", "gd", "1473" ], [ "Guadeloupe", "gp", "590", 0 ], [ "Guam", "gu", "1671" ], [ "Guatemala", "gt", "502" ], [ "Guernsey", "gg", "44", 1 ], [ "Guinea (Guinée)", "gn", "224" ], [ "Guinea-Bissau (Guiné Bissau)", "gw", "245" ], [ "Guyana", "gy", "592" ], [ "Haiti", "ht", "509" ], [ "Honduras", "hn", "504" ], [ "Hong Kong (香港)", "hk", "852" ], [ "Hungary (Magyarország)", "hu", "36" ], [ "Iceland (Ísland)", "is", "354" ], [ "India (भारत)", "in", "91" ], [ "Indonesia", "id", "62" ], [ "Iran (ایران)", "ir", "98" ], [ "Iraq (العراق)", "iq", "964" ], [ "Ireland", "ie", "353" ], [ "Isle of Man", "im", "44", 2 ], [ "Israel (ישראל)", "il", "972" ], [ "Italy (Italia)", "it", "39", 0 ], [ "Jamaica", "jm", "1876" ], [ "Japan (日本)", "jp", "81" ], [ "Jersey", "je", "44", 3 ], [ "Jordan (الأردن)", "jo", "962" ], [ "Kazakhstan (Казахстан)", "kz", "7", 1 ], [ "Kenya", "ke", "254" ], [ "Kiribati", "ki", "686" ], [ "Kosovo", "xk", "383" ], [ "Kuwait (الكويت)", "kw", "965" ], [ "Kyrgyzstan (Кыргызстан)", "kg", "996" ], [ "Laos (ລາວ)", "la", "856" ], [ "Latvia (Latvija)", "lv", "371" ], [ "Lebanon (لبنان)", "lb", "961" ], [ "Lesotho", "ls", "266" ], [ "Liberia", "lr", "231" ], [ "Libya (ليبيا)", "ly", "218" ], [ "Liechtenstein", "li", "423" ], [ "Lithuania (Lietuva)", "lt", "370" ], [ "Luxembourg", "lu", "352" ], [ "Macau (澳門)", "mo", "853" ], [ "Macedonia (FYROM) (Македонија)", "mk", "389" ], [ "Madagascar (Madagasikara)", "mg", "261" ], [ "Malawi", "mw", "265" ], [ "Malaysia", "my", "60" ], [ "Maldives", "mv", "960" ], [ "Mali", "ml", "223" ], [ "Malta", "mt", "356" ], [ "Marshall Islands", "mh", "692" ], [ "Martinique", "mq", "596" ], [ "Mauritania (موريتانيا)", "mr", "222" ], [ "Mauritius (Moris)", "mu", "230" ], [ "Mayotte", "yt", "262", 1 ], [ "Mexico (México)", "mx", "52" ], [ "Micronesia", "fm", "691" ], [ "Moldova (Republica Moldova)", "md", "373" ], [ "Monaco", "mc", "377" ], [ "Mongolia (Монгол)", "mn", "976" ], [ "Montenegro (Crna Gora)", "me", "382" ], [ "Montserrat", "ms", "1664" ], [ "Morocco (المغرب)", "ma", "212", 0 ], [ "Mozambique (Moçambique)", "mz", "258" ], [ "Myanmar (Burma) (မြန်မာ)", "mm", "95" ], [ "Namibia (Namibië)", "na", "264" ], [ "Nauru", "nr", "674" ], [ "Nepal (नेपाल)", "np", "977" ], [ "Netherlands (Nederland)", "nl", "31" ], [ "New Caledonia (Nouvelle-Calédonie)", "nc", "687" ], [ "New Zealand", "nz", "64" ], [ "Nicaragua", "ni", "505" ], [ "Niger (Nijar)", "ne", "227" ], [ "Nigeria", "ng", "234" ], [ "Niue", "nu", "683" ], [ "Norfolk Island", "nf", "672" ], [ "North Korea (조선 민주주의 인민 공화국)", "kp", "850" ], [ "Northern Mariana Islands", "mp", "1670" ], [ "Norway (Norge)", "no", "47", 0 ], [ "Oman (عُمان)", "om", "968" ], [ "Pakistan (پاکستان)", "pk", "92" ], [ "Palau", "pw", "680" ], [ "Palestine (فلسطين)", "ps", "970" ], [ "Panama (Panamá)", "pa", "507" ], [ "Papua New Guinea", "pg", "675" ], [ "Paraguay", "py", "595" ], [ "Peru (Perú)", "pe", "51" ], [ "Philippines", "ph", "63" ], [ "Poland (Polska)", "pl", "48" ], [ "Portugal", "pt", "351" ], [ "Puerto Rico", "pr", "1", 3, [ "787", "939" ] ], [ "Qatar (قطر)", "qa", "974" ], [ "Réunion (La Réunion)", "re", "262", 0 ], [ "Romania (România)", "ro", "40" ], [ "Russia (Россия)", "ru", "7", 0 ], [ "Rwanda", "rw", "250" ], [ "Saint Barthélemy", "bl", "590", 1 ], [ "Saint Helena", "sh", "290" ], [ "Saint Kitts and Nevis", "kn", "1869" ], [ "Saint Lucia", "lc", "1758" ], [ "Saint Martin (Saint-Martin (partie française))", "mf", "590", 2 ], [ "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)", "pm", "508" ], [ "Saint Vincent and the Grenadines", "vc", "1784" ], [ "Samoa", "ws", "685" ], [ "San Marino", "sm", "378" ], [ "São Tomé and Príncipe (São Tomé e Príncipe)", "st", "239" ], [ "Saudi Arabia (المملكة العربية السعودية)", "sa", "966" ], [ "Senegal (Sénégal)", "sn", "221" ], [ "Serbia (Србија)", "rs", "381" ], [ "Seychelles", "sc", "248" ], [ "Sierra Leone", "sl", "232" ], [ "Singapore", "sg", "65" ], [ "Sint Maarten", "sx", "1721" ], [ "Slovakia (Slovensko)", "sk", "421" ], [ "Slovenia (Slovenija)", "si", "386" ], [ "Solomon Islands", "sb", "677" ], [ "Somalia (Soomaaliya)", "so", "252" ], [ "South Africa", "za", "27" ], [ "South Korea (대한민국)", "kr", "82" ], [ "South Sudan (جنوب السودان)", "ss", "211" ], [ "Spain (España)", "es", "34" ], [ "Sri Lanka (ශ්රී ලංකාව)", "lk", "94" ], [ "Sudan (السودان)", "sd", "249" ], [ "Suriname", "sr", "597" ], [ "Svalbard and Jan Mayen", "sj", "47", 1 ], [ "Swaziland", "sz", "268" ], [ "Sweden (Sverige)", "se", "46" ], [ "Switzerland (Schweiz)", "ch", "41" ], [ "Syria (سوريا)", "sy", "963" ], [ "Taiwan (台灣)", "tw", "886" ], [ "Tajikistan", "tj", "992" ], [ "Tanzania", "tz", "255" ], [ "Thailand (ไทย)", "th", "66" ], [ "Timor-Leste", "tl", "670" ], [ "Togo", "tg", "228" ], [ "Tokelau", "tk", "690" ], [ "Tonga", "to", "676" ], [ "Trinidad and Tobago", "tt", "1868" ], [ "Tunisia (تونس)", "tn", "216" ], [ "Turkey (Türkiye)", "tr", "90" ], [ "Turkmenistan", "tm", "993" ], [ "Turks and Caicos Islands", "tc", "1649" ], [ "Tuvalu", "tv", "688" ], [ "U.S. Virgin Islands", "vi", "1340" ], [ "Uganda", "ug", "256" ], [ "Ukraine (Україна)", "ua", "380" ], [ "United Arab Emirates (الإمارات العربية المتحدة)", "ae", "971" ], [ "United Kingdom", "gb", "44", 0 ], [ "United States", "us", "1", 0 ], [ "Uruguay", "uy", "598" ], [ "Uzbekistan (Oʻzbekiston)", "uz", "998" ], [ "Vanuatu", "vu", "678" ], [ "Vatican City (Città del Vaticano)", "va", "39", 1 ], [ "Venezuela", "ve", "58" ], [ "Vietnam (Việt Nam)", "vn", "84" ], [ "Wallis and Futuna (Wallis-et-Futuna)", "wf", "681" ], [ "Western Sahara (الصحراء الغربية)", "eh", "212", 1 ], [ "Yemen (اليمن)", "ye", "967" ], [ "Zambia", "zm", "260" ], [ "Zimbabwe", "zw", "263" ], [ "Åland Islands", "ax", "358", 1 ] ];
1131 | // loop over all of the countries above
1132 | for (var i = 0; i < allCountries.length; i++) {
1133 | var c = allCountries[i];
1134 | allCountries[i] = {
1135 | name: c[0],
1136 | iso2: c[1],
1137 | dialCode: c[2],
1138 | priority: c[3] || 0,
1139 | areaCodes: c[4] || null
1140 | };
1141 | }
1142 | });
--------------------------------------------------------------------------------
/assets/intl-tel-input/js/intlTelInput.min.js:
--------------------------------------------------------------------------------
1 | /*
2 | * International Telephone Input v12.1.0
3 | * https://github.com/jackocnr/intl-tel-input.git
4 | * Licensed under the MIT license
5 | */
6 |
7 | !function(a){"function"==typeof define&&define.amd?define(["jquery"],function(b){a(b,window,document)}):"object"==typeof module&&module.exports?module.exports=a(require("jquery"),window,document):a(jQuery,window,document)}(function(a,b,c,d){"use strict";function e(b,c){this.a=a(b),this.b=a.extend({},h,c),this.ns="."+f+g++,this.d=Boolean(b.setSelectionRange),this.e=Boolean(a(b).attr("placeholder"))}var f="intlTelInput",g=1,h={allowDropdown:!0,autoHideDialCode:!0,autoPlaceholder:"polite",customPlaceholder:null,dropdownContainer:"",excludeCountries:[],formatOnDisplay:!0,geoIpLookup:null,hiddenInput:"",initialCountry:"",nationalMode:!0,onlyCountries:[],placeholderNumberType:"MOBILE",preferredCountries:["us","gb"],separateDialCode:!1,utilsScript:""},i={b:38,c:40,d:13,e:27,f:43,A:65,Z:90,j:32,k:9},j=["800","822","833","844","855","866","877","880","881","882","883","884","885","886","887","888","889"];a(b).on("load",function(){a.fn[f].windowLoaded=!0}),e.prototype={_a:function(){return this.b.nationalMode&&(this.b.autoHideDialCode=!1),this.b.separateDialCode&&(this.b.autoHideDialCode=this.b.nationalMode=!1),this.g=/Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),this.g&&(a("body").addClass("iti-mobile"),this.b.dropdownContainer||(this.b.dropdownContainer="body")),this.h=new a.Deferred,this.i=new a.Deferred,this.s={},this._b(),this._f(),this._h(),this._i(),this._i2(),[this.h,this.i]},_b:function(){this._d(),this._d2(),this._e()},_c:function(a,b,c){b in this.q||(this.q[b]=[]);var d=c||0;this.q[b][d]=a},_d:function(){if(this.b.onlyCountries.length){var a=this.b.onlyCountries.map(function(a){return a.toLowerCase()});this.p=k.filter(function(b){return a.indexOf(b.iso2)>-1})}else if(this.b.excludeCountries.length){var b=this.b.excludeCountries.map(function(a){return a.toLowerCase()});this.p=k.filter(function(a){return-1===b.indexOf(a.iso2)})}else this.p=k},_d2:function(){this.q={};for(var a=0;a",{"class":b})),this.k=a("