Created
October 22, 2014 12:36
-
-
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;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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