123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125 |
- (function(factory) {
- if (typeof define === "function" && define.amd) {
- define([ "jquery" ], function($) {
- factory($, window, document);
- });
- } else if (typeof module === "object" && module.exports) {
- module.exports = factory(require("jquery"), window, document);
- } else {
- factory(jQuery, window, document);
- }
- })(function($, window, document, undefined) {
- "use strict";
-
- var pluginName = "intlTelInput", id = 1,
- defaults = {
-
- allowDropdown: true,
-
- autoHideDialCode: true,
-
- autoPlaceholder: "polite",
-
- customPlaceholder: null,
-
- dropdownContainer: "",
-
- excludeCountries: [],
-
- formatOnDisplay: true,
-
- geoIpLookup: null,
-
- initialCountry: "",
-
- nationalMode: true,
-
- onlyCountries: [],
-
- placeholderNumberType: "MOBILE",
-
- preferredCountries: [ "us", "gb" ],
-
- separateDialCode: false,
-
- utilsScript: ""
- }, keys = {
- UP: 38,
- DOWN: 40,
- ENTER: 13,
- ESC: 27,
- PLUS: 43,
- A: 65,
- Z: 90,
- SPACE: 32,
- TAB: 9
- },
- regionlessNanpNumbers = [ "800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889" ];
-
- $(window).on("load", function() {
-
- $.fn[pluginName].windowLoaded = true;
- });
- function Plugin(element, options) {
- this.telInput = $(element);
- this.options = $.extend({}, defaults, options);
-
- this.ns = "." + pluginName + id++;
-
- this.isGoodBrowser = Boolean(element.setSelectionRange);
- this.hadInitialPlaceholder = Boolean($(element).attr("placeholder"));
- }
- Plugin.prototype = {
- _init: function() {
-
- if (this.options.nationalMode) {
- this.options.autoHideDialCode = false;
- }
-
- if (this.options.separateDialCode) {
- this.options.autoHideDialCode = this.options.nationalMode = false;
- }
-
-
-
- this.isMobile = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
- if (this.isMobile) {
-
- $("body").addClass("iti-mobile");
-
- if (!this.options.dropdownContainer) {
- this.options.dropdownContainer = "body";
- }
- }
-
-
- this.autoCountryDeferred = new $.Deferred();
- this.utilsScriptDeferred = new $.Deferred();
-
- this.selectedCountryData = {};
-
- this._processCountryData();
-
- this._generateMarkup();
-
- this._setInitialState();
-
- this._initListeners();
-
- this._initRequests();
-
- return [ this.autoCountryDeferred, this.utilsScriptDeferred ];
- },
-
-
- _processCountryData: function() {
-
- this._processAllCountries();
-
- this._processCountryCodes();
-
- this._processPreferredCountries();
- },
-
- _addCountryCode: function(iso2, dialCode, priority) {
- if (!(dialCode in this.countryCodes)) {
- this.countryCodes[dialCode] = [];
- }
- var index = priority || 0;
- this.countryCodes[dialCode][index] = iso2;
- },
-
- _filterCountries: function(countryArray, processFunc) {
- var i;
-
- for (i = 0; i < countryArray.length; i++) {
- countryArray[i] = countryArray[i].toLowerCase();
- }
-
- this.countries = [];
- for (i = 0; i < allCountries.length; i++) {
- if (processFunc($.inArray(allCountries[i].iso2, countryArray))) {
- this.countries.push(allCountries[i]);
- }
- }
- },
-
- _processAllCountries: function() {
- if (this.options.onlyCountries.length) {
-
- this._filterCountries(this.options.onlyCountries, function(arrayPos) {
-
- return arrayPos > -1;
- });
- } else if (this.options.excludeCountries.length) {
-
- this._filterCountries(this.options.excludeCountries, function(arrayPos) {
-
- return arrayPos == -1;
- });
- } else {
- this.countries = allCountries;
- }
- },
-
- _processCountryCodes: function() {
- this.countryCodes = {};
- for (var i = 0; i < this.countries.length; i++) {
- var c = this.countries[i];
- this._addCountryCode(c.iso2, c.dialCode, c.priority);
-
- if (c.areaCodes) {
- for (var j = 0; j < c.areaCodes.length; j++) {
-
- this._addCountryCode(c.iso2, c.dialCode + c.areaCodes[j]);
- }
- }
- }
- },
-
- _processPreferredCountries: function() {
- this.preferredCountries = [];
- for (var i = 0; i < this.options.preferredCountries.length; i++) {
- var countryCode = this.options.preferredCountries[i].toLowerCase(), countryData = this._getCountryData(countryCode, false, true);
- if (countryData) {
- this.preferredCountries.push(countryData);
- }
- }
- },
-
- _generateMarkup: function() {
-
- this.telInput.attr("autocomplete", "off");
-
- var parentClass = "intl-tel-input";
- if (this.options.allowDropdown) {
- parentClass += " allow-dropdown";
- }
- if (this.options.separateDialCode) {
- parentClass += " separate-dial-code";
- }
- this.telInput.wrap($("<div>", {
- "class": parentClass
- }));
- this.flagsContainer = $("<div>", {
- "class": "flag-container"
- }).insertBefore(this.telInput);
-
- var selectedFlag = $("<div>", {
- "class": "selected-flag"
- });
- selectedFlag.appendTo(this.flagsContainer);
- this.selectedFlagInner = $("<div>", {
- "class": "iti-flag"
- }).appendTo(selectedFlag);
- if (this.options.separateDialCode) {
- this.selectedDialCode = $("<div>", {
- "class": "selected-dial-code"
- }).appendTo(selectedFlag);
- }
- if (this.options.allowDropdown) {
-
- selectedFlag.attr("tabindex", "0");
-
- $("<div>", {
- "class": "iti-arrow"
- }).appendTo(selectedFlag);
-
- this.countryList = $("<ul>", {
- "class": "country-list hide"
- });
- if (this.preferredCountries.length) {
- this._appendListItems(this.preferredCountries, "preferred");
- $("<li>", {
- "class": "divider"
- }).appendTo(this.countryList);
- }
- this._appendListItems(this.countries, "");
-
- this.countryListItems = this.countryList.children(".country");
-
- if (this.options.dropdownContainer) {
- this.dropdown = $("<div>", {
- "class": "intl-tel-input iti-container"
- }).append(this.countryList);
- } else {
- this.countryList.appendTo(this.flagsContainer);
- }
- } else {
-
- this.countryListItems = $();
- }
- },
-
- _appendListItems: function(countries, className) {
-
-
- var tmp = "";
-
- for (var i = 0; i < countries.length; i++) {
- var c = countries[i];
-
- tmp += "<li class='country " + className + "' data-dial-code='" + c.dialCode + "' data-country-code='" + c.iso2 + "'>";
-
- tmp += "<div class='flag-box'><div class='iti-flag " + c.iso2 + "'></div></div>";
-
- tmp += "<span class='country-name'>" + c.name + "</span>";
- tmp += "<span class='dial-code'>+" + c.dialCode + "</span>";
-
- tmp += "</li>";
- }
- this.countryList.append(tmp);
- },
-
-
-
-
-
- _setInitialState: function() {
- var val = this.telInput.val();
-
- if (this._getDialCode(val) && !this._isRegionlessNanp(val)) {
- this._updateFlagFromNumber(val);
- } else if (this.options.initialCountry !== "auto") {
-
- if (this.options.initialCountry) {
- this._setFlag(this.options.initialCountry.toLowerCase());
- } else {
-
- this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2;
- if (!val) {
- this._setFlag(this.defaultCountry);
- }
- }
-
- if (!val && !this.options.nationalMode && !this.options.autoHideDialCode && !this.options.separateDialCode) {
- this.telInput.val("+" + this.selectedCountryData.dialCode);
- }
- }
-
-
- if (val) {
-
- this._updateValFromNumber(val);
- }
- },
-
- _initListeners: function() {
- this._initKeyListeners();
- if (this.options.autoHideDialCode) {
- this._initFocusListeners();
- }
- if (this.options.allowDropdown) {
- this._initDropdownListeners();
- }
- },
-
- _initDropdownListeners: function() {
- var that = this;
-
- var label = this.telInput.closest("label");
- if (label.length) {
- label.on("click" + this.ns, function(e) {
-
- if (that.countryList.hasClass("hide")) {
- that.telInput.focus();
- } else {
- e.preventDefault();
- }
- });
- }
-
- var selectedFlag = this.selectedFlagInner.parent();
- selectedFlag.on("click" + this.ns, function(e) {
-
-
-
- if (that.countryList.hasClass("hide") && !that.telInput.prop("disabled") && !that.telInput.prop("readonly")) {
- that._showDropdown();
- }
- });
-
- this.flagsContainer.on("keydown" + that.ns, function(e) {
- var isDropdownHidden = that.countryList.hasClass("hide");
- if (isDropdownHidden && (e.which == keys.UP || e.which == keys.DOWN || e.which == keys.SPACE || e.which == keys.ENTER)) {
-
- e.preventDefault();
-
- e.stopPropagation();
- that._showDropdown();
- }
-
- if (e.which == keys.TAB) {
- that._closeDropdown();
- }
- });
- },
-
- _initRequests: function() {
- var that = this;
-
- if (this.options.utilsScript) {
-
- if ($.fn[pluginName].windowLoaded) {
- $.fn[pluginName].loadUtils(this.options.utilsScript, this.utilsScriptDeferred);
- } else {
-
- $(window).on("load", function() {
- $.fn[pluginName].loadUtils(that.options.utilsScript, that.utilsScriptDeferred);
- });
- }
- } else {
- this.utilsScriptDeferred.resolve();
- }
- if (this.options.initialCountry === "auto") {
- this._loadAutoCountry();
- } else {
- this.autoCountryDeferred.resolve();
- }
- },
-
- _loadAutoCountry: function() {
- var that = this;
-
-
-
-
- if ($.fn[pluginName].autoCountry) {
- this.handleAutoCountry();
- } else if (!$.fn[pluginName].startedLoadingAutoCountry) {
-
- $.fn[pluginName].startedLoadingAutoCountry = true;
- if (typeof this.options.geoIpLookup === "function") {
- this.options.geoIpLookup(function(countryCode) {
- $.fn[pluginName].autoCountry = countryCode.toLowerCase();
-
-
-
- setTimeout(function() {
- $(".intl-tel-input input").intlTelInput("handleAutoCountry");
- });
- });
- }
- }
- },
-
- _initKeyListeners: function() {
- var that = this;
-
-
- this.telInput.on("keyup" + this.ns, function() {
- if (that._updateFlagFromNumber(that.telInput.val())) {
- that._triggerCountryChange();
- }
- });
-
- this.telInput.on("cut" + this.ns + " paste" + this.ns, function() {
-
- setTimeout(function() {
- if (that._updateFlagFromNumber(that.telInput.val())) {
- that._triggerCountryChange();
- }
- });
- });
- },
-
- _cap: function(number) {
- var max = this.telInput.attr("maxlength");
- return max && number.length > max ? number.substr(0, max) : number;
- },
-
- _initFocusListeners: function() {
- var that = this;
-
- this.telInput.on("mousedown" + this.ns, function(e) {
- if (!that.telInput.is(":focus") && !that.telInput.val()) {
- e.preventDefault();
-
- that.telInput.focus();
- }
- });
-
- this.telInput.on("focus" + this.ns, function(e) {
- if (!that.telInput.val() && !that.telInput.prop("readonly") && that.selectedCountryData.dialCode) {
-
- that.telInput.val("+" + that.selectedCountryData.dialCode);
-
- that.telInput.one("keypress.plus" + that.ns, function(e) {
- if (e.which == keys.PLUS) {
- that.telInput.val("");
- }
- });
-
- setTimeout(function() {
- var input = that.telInput[0];
- if (that.isGoodBrowser) {
- var len = that.telInput.val().length;
- input.setSelectionRange(len, len);
- }
- });
- }
- });
-
- var form = this.telInput.prop("form");
- if (form) {
- $(form).on("submit" + this.ns, function() {
- that._removeEmptyDialCode();
- });
- }
- this.telInput.on("blur" + this.ns, function() {
- that._removeEmptyDialCode();
- });
- },
- _removeEmptyDialCode: function() {
- var value = this.telInput.val(), startsPlus = value.charAt(0) == "+";
- if (startsPlus) {
- var numeric = this._getNumeric(value);
-
- if (!numeric || this.selectedCountryData.dialCode == numeric) {
- this.telInput.val("");
- }
- }
-
- this.telInput.off("keypress.plus" + this.ns);
- },
-
- _getNumeric: function(s) {
- return s.replace(/\D/g, "");
- },
-
- _showDropdown: function() {
- this._setDropdownPosition();
-
- var activeListItem = this.countryList.children(".active");
- if (activeListItem.length) {
- this._highlightListItem(activeListItem);
- this._scrollTo(activeListItem);
- }
-
- this._bindDropdownListeners();
-
- this.selectedFlagInner.children(".iti-arrow").addClass("up");
- },
-
- _setDropdownPosition: function() {
- var that = this;
- if (this.options.dropdownContainer) {
- this.dropdown.appendTo(this.options.dropdownContainer);
- }
-
- this.dropdownHeight = this.countryList.removeClass("hide").outerHeight();
- if (!this.isMobile) {
- var pos = this.telInput.offset(), inputTop = pos.top, windowTop = $(window).scrollTop(),
- dropdownFitsBelow = inputTop + this.telInput.outerHeight() + this.dropdownHeight < windowTop + $(window).height(), dropdownFitsAbove = inputTop - this.dropdownHeight > windowTop;
-
- this.countryList.toggleClass("dropup", !dropdownFitsBelow && dropdownFitsAbove);
-
- if (this.options.dropdownContainer) {
-
- var extraTop = !dropdownFitsBelow && dropdownFitsAbove ? 0 : this.telInput.innerHeight();
-
- this.dropdown.css({
- top: inputTop + extraTop,
- left: pos.left
- });
-
- $(window).on("scroll" + this.ns, function() {
- that._closeDropdown();
- });
- }
- }
- },
-
- _bindDropdownListeners: function() {
- var that = this;
-
-
- this.countryList.on("mouseover" + this.ns, ".country", function(e) {
- that._highlightListItem($(this));
- });
-
- this.countryList.on("click" + this.ns, ".country", function(e) {
- that._selectListItem($(this));
- });
-
-
-
- var isOpening = true;
- $("html").on("click" + this.ns, function(e) {
- if (!isOpening) {
- that._closeDropdown();
- }
- isOpening = false;
- });
-
-
-
-
- var query = "", queryTimer = null;
- $(document).on("keydown" + this.ns, function(e) {
-
-
- e.preventDefault();
- if (e.which == keys.UP || e.which == keys.DOWN) {
-
- that._handleUpDownKey(e.which);
- } else if (e.which == keys.ENTER) {
-
- that._handleEnterKey();
- } else if (e.which == keys.ESC) {
-
- that._closeDropdown();
- } else if (e.which >= keys.A && e.which <= keys.Z || e.which == keys.SPACE) {
-
-
- if (queryTimer) {
- clearTimeout(queryTimer);
- }
- query += String.fromCharCode(e.which);
- that._searchForCountry(query);
-
- queryTimer = setTimeout(function() {
- query = "";
- }, 1e3);
- }
- });
- },
-
- _handleUpDownKey: function(key) {
- var current = this.countryList.children(".highlight").first();
- var next = key == keys.UP ? current.prev() : current.next();
- if (next.length) {
-
- if (next.hasClass("divider")) {
- next = key == keys.UP ? next.prev() : next.next();
- }
- this._highlightListItem(next);
- this._scrollTo(next);
- }
- },
-
- _handleEnterKey: function() {
- var currentCountry = this.countryList.children(".highlight").first();
- if (currentCountry.length) {
- this._selectListItem(currentCountry);
- }
- },
-
- _searchForCountry: function(query) {
- for (var i = 0; i < this.countries.length; i++) {
- if (this._startsWith(this.countries[i].name, query)) {
- var listItem = this.countryList.children("[data-country-code=" + this.countries[i].iso2 + "]").not(".preferred");
-
- this._highlightListItem(listItem);
- this._scrollTo(listItem, true);
- break;
- }
- }
- },
-
- _startsWith: function(a, b) {
- return a.substr(0, b.length).toUpperCase() == b;
- },
-
-
- _updateValFromNumber: function(number) {
- if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) {
- var format = !this.options.separateDialCode && (this.options.nationalMode || number.charAt(0) != "+") ? intlTelInputUtils.numberFormat.NATIONAL : intlTelInputUtils.numberFormat.INTERNATIONAL;
- number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format);
- }
- number = this._beforeSetNumber(number);
- this.telInput.val(number);
- },
-
-
- _updateFlagFromNumber: function(number) {
-
-
- if (number && this.options.nationalMode && this.selectedCountryData.dialCode == "1" && number.charAt(0) != "+") {
- if (number.charAt(0) != "1") {
- number = "1" + number;
- }
- number = "+" + number;
- }
-
- var dialCode = this._getDialCode(number), countryCode = null, numeric = this._getNumeric(number);
- if (dialCode) {
-
- var countryCodes = this.countryCodes[this._getNumeric(dialCode)], alreadySelected = $.inArray(this.selectedCountryData.iso2, countryCodes) > -1,
- isNanpAreaCode = dialCode == "+1" && numeric.length >= 4, nanpSelected = this.selectedCountryData.dialCode == "1";
-
-
-
-
- if (!(nanpSelected && this._isRegionlessNanp(numeric)) && (!alreadySelected || isNanpAreaCode)) {
-
- for (var j = 0; j < countryCodes.length; j++) {
- if (countryCodes[j]) {
- countryCode = countryCodes[j];
- break;
- }
- }
- }
- } else if (number.charAt(0) == "+" && numeric.length) {
-
-
- countryCode = "";
- } else if (!number || number == "+") {
-
- countryCode = this.defaultCountry;
- }
- if (countryCode !== null) {
- return this._setFlag(countryCode);
- }
- return false;
- },
-
- _isRegionlessNanp: function(number) {
- var numeric = this._getNumeric(number);
- if (numeric.charAt(0) == "1") {
- var areaCode = numeric.substr(1, 3);
- return $.inArray(areaCode, regionlessNanpNumbers) > -1;
- }
- return false;
- },
-
- _highlightListItem: function(listItem) {
- this.countryListItems.removeClass("highlight");
- listItem.addClass("highlight");
- },
-
-
- _getCountryData: function(countryCode, ignoreOnlyCountriesOption, allowFail) {
- var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries;
- for (var i = 0; i < countryList.length; i++) {
- if (countryList[i].iso2 == countryCode) {
- return countryList[i];
- }
- }
- if (allowFail) {
- return null;
- } else {
- throw new Error("No country data for '" + countryCode + "'");
- }
- },
-
-
- _setFlag: function(countryCode) {
- var prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {};
-
- this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {};
-
- if (this.selectedCountryData.iso2) {
- this.defaultCountry = this.selectedCountryData.iso2;
- }
- this.selectedFlagInner.attr("class", "iti-flag " + countryCode);
-
- var title = countryCode ? this.selectedCountryData.name + ": +" + this.selectedCountryData.dialCode : "Unknown";
- this.selectedFlagInner.parent().attr("title", title);
- if (this.options.separateDialCode) {
- var dialCode = this.selectedCountryData.dialCode ? "+" + this.selectedCountryData.dialCode : "", parent = this.telInput.parent();
- if (prevCountry.dialCode) {
- parent.removeClass("iti-sdc-" + (prevCountry.dialCode.length + 1));
- }
- if (dialCode) {
- parent.addClass("iti-sdc-" + dialCode.length);
- }
- this.selectedDialCode.text(dialCode);
- }
-
- this._updatePlaceholder();
-
- this.countryListItems.removeClass("active");
- if (countryCode) {
- this.countryListItems.find(".iti-flag." + countryCode).first().closest(".country").addClass("active");
- }
-
- return prevCountry.iso2 !== countryCode;
- },
-
- _updatePlaceholder: function() {
- var shouldSetPlaceholder = this.options.autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && (this.options.autoPlaceholder === true || this.options.autoPlaceholder === "polite");
- if (window.intlTelInputUtils && shouldSetPlaceholder) {
- var numberType = intlTelInputUtils.numberType[this.options.placeholderNumberType], placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, this.options.nationalMode, numberType) : "";
- placeholder = this._beforeSetNumber(placeholder);
- if (typeof this.options.customPlaceholder === "function") {
- placeholder = this.options.customPlaceholder(placeholder, this.selectedCountryData);
- }
- this.telInput.attr("placeholder", placeholder);
- }
- },
-
- _selectListItem: function(listItem) {
-
- var flagChanged = this._setFlag(listItem.attr("data-country-code"));
- this._closeDropdown();
- this._updateDialCode(listItem.attr("data-dial-code"), true);
-
- this.telInput.focus();
-
- if (this.isGoodBrowser) {
- var len = this.telInput.val().length;
- this.telInput[0].setSelectionRange(len, len);
- }
- if (flagChanged) {
- this._triggerCountryChange();
- }
- },
-
- _closeDropdown: function() {
- this.countryList.addClass("hide");
-
- this.selectedFlagInner.children(".iti-arrow").removeClass("up");
-
- $(document).off(this.ns);
-
- $("html").off(this.ns);
-
- this.countryList.off(this.ns);
-
- if (this.options.dropdownContainer) {
- if (!this.isMobile) {
- $(window).off("scroll" + this.ns);
- }
- this.dropdown.detach();
- }
- },
-
- _scrollTo: function(element, middle) {
- 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;
- if (elementTop < containerTop) {
-
- if (middle) {
- newScrollTop -= middleOffset;
- }
- container.scrollTop(newScrollTop);
- } else if (elementBottom > containerBottom) {
-
- if (middle) {
- newScrollTop += middleOffset;
- }
- var heightDifference = containerHeight - elementHeight;
- container.scrollTop(newScrollTop - heightDifference);
- }
- },
-
-
- _updateDialCode: function(newDialCode, hasSelectedListItem) {
- var inputVal = this.telInput.val(), newNumber;
-
- newDialCode = "+" + newDialCode;
- if (inputVal.charAt(0) == "+") {
-
- var prevDialCode = this._getDialCode(inputVal);
- if (prevDialCode) {
-
- newNumber = inputVal.replace(prevDialCode, newDialCode);
- } else {
-
-
- newNumber = newDialCode;
- }
- } else if (this.options.nationalMode || this.options.separateDialCode) {
-
- return;
- } else {
-
- if (inputVal) {
-
- newNumber = newDialCode + inputVal;
- } else if (hasSelectedListItem || !this.options.autoHideDialCode) {
-
- newNumber = newDialCode;
- } else {
- return;
- }
- }
- this.telInput.val(newNumber);
- },
-
-
- _getDialCode: function(number) {
- var dialCode = "";
-
- if (number.charAt(0) == "+") {
- var numericChars = "";
-
- for (var i = 0; i < number.length; i++) {
- var c = number.charAt(i);
-
- if ($.isNumeric(c)) {
- numericChars += c;
-
- if (this.countryCodes[numericChars]) {
-
- dialCode = number.substr(0, i + 1);
- }
-
- if (numericChars.length == 4) {
- break;
- }
- }
- }
- }
- return dialCode;
- },
-
- _getFullNumber: function() {
- var val = $.trim(this.telInput.val()), dialCode = this.selectedCountryData.dialCode, prefix, numericVal = this._getNumeric(val),
- normalizedVal = numericVal.charAt(0) == "1" ? numericVal : "1" + numericVal;
- if (this.options.separateDialCode) {
- prefix = "+" + dialCode;
- } else if (val.charAt(0) != "+" && val.charAt(0) != "1" && dialCode && dialCode.charAt(0) == "1" && dialCode.length == 4 && dialCode != normalizedVal.substr(0, 4)) {
-
- prefix = dialCode.substr(1);
- } else {
- prefix = "";
- }
- return prefix + val;
- },
-
- _beforeSetNumber: function(number) {
- if (this.options.separateDialCode) {
- var dialCode = this._getDialCode(number);
- if (dialCode) {
-
-
-
-
- if (this.selectedCountryData.areaCodes !== null) {
- dialCode = "+" + this.selectedCountryData.dialCode;
- }
-
-
- var start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
- number = number.substr(start);
- }
- }
- return this._cap(number);
- },
-
- _triggerCountryChange: function() {
- this.telInput.trigger("countrychange", this.selectedCountryData);
- },
-
-
- handleAutoCountry: function() {
- if (this.options.initialCountry === "auto") {
-
- this.defaultCountry = $.fn[pluginName].autoCountry;
-
- if (!this.telInput.val()) {
- this.setCountry(this.defaultCountry);
- }
- this.autoCountryDeferred.resolve();
- }
- },
-
- handleUtils: function() {
-
- if (window.intlTelInputUtils) {
-
- if (this.telInput.val()) {
- this._updateValFromNumber(this.telInput.val());
- }
- this._updatePlaceholder();
- }
- this.utilsScriptDeferred.resolve();
- },
-
-
- destroy: function() {
- if (this.allowDropdown) {
-
- this._closeDropdown();
-
- this.selectedFlagInner.parent().off(this.ns);
-
- this.telInput.closest("label").off(this.ns);
- }
-
- if (this.options.autoHideDialCode) {
- var form = this.telInput.prop("form");
- if (form) {
- $(form).off(this.ns);
- }
- }
-
- this.telInput.off(this.ns);
-
- var container = this.telInput.parent();
- container.before(this.telInput).remove();
- },
-
- getExtension: function() {
- if (window.intlTelInputUtils) {
- return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2);
- }
- return "";
- },
-
- getNumber: function(format) {
- if (window.intlTelInputUtils) {
- return intlTelInputUtils.formatNumber(this._getFullNumber(), this.selectedCountryData.iso2, format);
- }
- return "";
- },
-
- getNumberType: function() {
- if (window.intlTelInputUtils) {
- return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2);
- }
- return -99;
- },
-
- getSelectedCountryData: function() {
- return this.selectedCountryData;
- },
-
- getValidationError: function() {
- if (window.intlTelInputUtils) {
- return intlTelInputUtils.getValidationError(this._getFullNumber(), this.selectedCountryData.iso2);
- }
- return -99;
- },
-
- isValidNumber: function() {
- var val = $.trim(this._getFullNumber()), countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : "";
- return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null;
- },
-
- setCountry: function(countryCode) {
- countryCode = countryCode.toLowerCase();
-
- if (!this.selectedFlagInner.hasClass(countryCode)) {
- this._setFlag(countryCode);
- this._updateDialCode(this.selectedCountryData.dialCode, false);
- this._triggerCountryChange();
- }
- },
-
- setNumber: function(number) {
-
- var flagChanged = this._updateFlagFromNumber(number);
- this._updateValFromNumber(number);
- if (flagChanged) {
- this._triggerCountryChange();
- }
- }
- };
-
-
- $.fn[pluginName] = function(options) {
- var args = arguments;
-
-
- if (options === undefined || typeof options === "object") {
-
- var deferreds = [];
- this.each(function() {
- if (!$.data(this, "plugin_" + pluginName)) {
- var instance = new Plugin(this, options);
- var instanceDeferreds = instance._init();
-
- deferreds.push(instanceDeferreds[0]);
- deferreds.push(instanceDeferreds[1]);
- $.data(this, "plugin_" + pluginName, instance);
- }
- });
-
- return $.when.apply(null, deferreds);
- } else if (typeof options === "string" && options[0] !== "_") {
-
-
-
-
- var returns;
- this.each(function() {
- var instance = $.data(this, "plugin_" + pluginName);
-
-
- if (instance instanceof Plugin && typeof instance[options] === "function") {
-
-
- returns = instance[options].apply(instance, Array.prototype.slice.call(args, 1));
- }
-
- if (options === "destroy") {
- $.data(this, "plugin_" + pluginName, null);
- }
- });
-
-
- return returns !== undefined ? returns : this;
- }
- };
-
-
- $.fn[pluginName].getCountryData = function() {
- return allCountries;
- };
-
- $.fn[pluginName].loadUtils = function(path, utilsScriptDeferred) {
- if (!$.fn[pluginName].loadedUtilsScript) {
-
- $.fn[pluginName].loadedUtilsScript = true;
-
- $.ajax({
- type: "GET",
- url: path,
- complete: function() {
-
- $(".intl-tel-input input").intlTelInput("handleUtils");
- },
- dataType: "script",
- cache: true
- });
- } else if (utilsScriptDeferred) {
- utilsScriptDeferred.resolve();
- }
- };
-
- $.fn[pluginName].defaults = defaults;
-
- $.fn[pluginName].version = "11.0.4";
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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 (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", "wf", "681" ], [ "Western Sahara (الصحراء الغربية)", "eh", "212", 1 ], [ "Yemen (اليمن)", "ye", "967" ], [ "Zambia", "zm", "260" ], [ "Zimbabwe", "zw", "263" ], [ "Åland Islands", "ax", "358", 1 ] ];
-
- for (var i = 0; i < allCountries.length; i++) {
- var c = allCountries[i];
- allCountries[i] = {
- name: c[0],
- iso2: c[1],
- dialCode: c[2],
- priority: c[3] || 0,
- areaCodes: c[4] || null
- };
- }
- });
|