Skip to content

Instantly share code, notes, and snippets.

@mrladeia
Created April 5, 2019 19:36
Show Gist options
  • Save mrladeia/02024d49b7ff7d40f192edd0559f162f to your computer and use it in GitHub Desktop.
Save mrladeia/02024d49b7ff7d40f192edd0559f162f to your computer and use it in GitHub Desktop.
if ($("input#mobileNumber").length) {
var input = document.querySelector("input#mobileNumber");
window.intlTelInput(input, {
//initialCountry: "br",
autoPlaceHolder: "agressive",
utilsScript: "/vendors/js/tel-input/js/utils.js",
initialCountry: "auto",
preferredCountries: ["br", "pt", "us"],
geoIpLookup: function (callback) {
$.get('https://ipinfo.io', function () {
}, "jsonp").always(function (resp) {
var countryCode = (resp && resp.country) ? resp.country : "BR";
callback(countryCode);
});
},
customPlaceholder: function (selectedCountryPlaceholder, selectedCountryData) {
input.addEventListener("focus", function (event) {
var im = new Inputmask(selectedCountryPlaceholder.replace(new RegExp("[0-9]", "g"), "9"));
im.mask(event.target);
});
input.addEventListener("mouseover", function (event) {
input.setAttribute('placeholder', selectedCountryPlaceholder)
});
input.addEventListener("mouseout", function (event) {
event.target.setAttribute('placeholder', "Telefone Celular")
});
return "Telefone Celular";
}
});
} else if ($("input#numberPhone").length) {
var input = document.querySelector("input#numberPhone");
window.intlTelInput(input, {
//initialCountry: "br",
autoPlaceHolder: "agressive",
utilsScript: "/vendors/js/tel-input/js/utils.js",
initialCountry: "auto",
preferredCountries: ["br", "pt", "us"],
geoIpLookup: function (callback) {
$.get('https://ipinfo.io', function () {
}, "jsonp").always(function (resp) {
var countryCode = (resp && resp.country) ? resp.country : "BR";
callback(countryCode);
});
},
customPlaceholder: function (selectedCountryPlaceholder, selectedCountryData) {
input.addEventListener("focus", function (event) {
var im = new Inputmask(selectedCountryPlaceholder.replace(new RegExp("[0-9]", "g"), "9"));
im.mask(event.target);
});
input.addEventListener("mouseover", function (event) {
input.setAttribute('placeholder', selectedCountryPlaceholder)
});
input.addEventListener("mouseout", function (event) {
event.target.setAttribute('placeholder', "Telefone Celular")
});
return "Telefone Celular";
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment