Skip to content

Instantly share code, notes, and snippets.

@frankdors
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankdors/2f554488a1231dbcea8b to your computer and use it in GitHub Desktop.
Save frankdors/2f554488a1231dbcea8b to your computer and use it in GitHub Desktop.
Ajusta masked-input-plugin pra funcionar no Android
if( /android/i.test( navigator.userAgent ) )
{
// Extende função p/ Funcionar com Android
$.fn.mask = (function( mask ){ return function(){
// Guarda Originais
var input = this, args = arguments, myMask = args[0].replace('?','');
// Coloca toda mascara como Condicional
if( myMask.substring(0,1) !== '?' ){
args[0] = '?'+ myMask;
}
// Monitora Foco e Blur
input.unbind('.fnMask')
.bind('focus.fnMask', function(){
input.unmask();
// Retorna vazio se não tiver nada
if( this.value.replace(/\D/g,'') === '' ){
this.value = '';
};
// Adiciona Mascara como Placeholder
if('placeholder' in this && this.placeholder === ''){
this.placeholder = myMask;
}
})
.bind('blur.fnMask', function(){
mask.apply(input, args);
// Remove Mascara como Placeholder
if('placeholder' in this && this.placeholder === myMask){
this.placeholder = '';
}
});
// Remove Mascara como Placeholder
if('placeholder' in this[0] && this[0].placeholder === myMask){
this[0].placeholder = '';
}
// Executa a função original
return mask.apply(input, args);
};})( $.fn.mask ); // Passa a Original
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment