Skip to content

Instantly share code, notes, and snippets.

@Falci
Created October 22, 2014 12:36
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 Falci/68162ca204eb1f4a908d to your computer and use it in GitHub Desktop.
Save Falci/68162ca204eb1f4a908d to your computer and use it in GitHub Desktop.
CodeReader: verifica se o campo está recebendo dados pelo teclado ou pelo leitor de código de barras;
$.fn.codeReader = function(options){
var timer, defaults = {
event: 'keypress',
max: 100,
fail: function(){
console.error('keyboard');
},
success: function(str){
console.log(str);
}
};
var op = $.extend({}, defaults, options);
this.on(op.event, function(e){
clearTimeout(timer);
if(e.which == 13){
e.preventDefault();
return op.success( $(this).val() );
}
timer = setTimeout(op.fail, op.max);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment