Puslīdz pāveidoju. Skaisti tas, šķiet, nav, bet dara apmēram to pašu, ko oriģināls.
function CardInputCheck(inputFieldElement, opOptions) {
if (opOptions!=null) this.options = opOptions;
this.element = $(inputFieldElement);
var self = this;
// focus the input field in question, so when the card is swiped, the output is written in this input field
if(this.element) { // && $type(this.element) == 'element') {
this.element.bind('keyup', function(event) {
var v = $(self.element).val();
if(v.length == self.options.readerOutputLength && v.match(self.options.readerOutputRE)) {
$(self.element).val(v.substr(8, 10)); // extract the actual card number from the reader's output
self.success();
}
});
this.focusElement(); // for firefox (the delayed focus does not work for some reason)
//this.focusElement.delay(200, this); // for all other browsers, who are not ready for immediate focusing
}
}
CardInputCheck.prototype.options = {
readerOutputLength: 117, // number of characters in the card reader output
readerOutputRE: /^\%B\d{16}\^\s+\^\d+\?;\d+=\d+\?$/, // regexp for the card reader output
focusOnSuccess: null, // element to focus on success
onSuccess: null // function to execute on success
};
CardInputCheck.prototype.success = function() {
if(this.options.focusOnSuccess && this.options.focusOnSuccess.focus) {
try {
this.options.focusOnSuccess.focus();
} catch(e) {
}
}
if(this.options.onSuccess!=null){
this.options.onSuccess();
}
}
CardInputCheck.prototype.focusElement = function() {
try {
// focus method for some reason sometimes throws errors...
this.element.focus();
} catch(e) {
}
}
/*#########################################################################################################################*/
//pieliekam jQuery modelim metodi "CardInputCheck"
$.fn.CardInputCheck = function(options) {
return this.each( function() {
var oCheck = new CardInputCheck($(this), options);
})
};
//dokumentam onload ar selektoru atrodam vajadzīgos elementusu un tiem izveicam CardInputCheck
$(document).ready(
function(){
$("#kuu").CardInputCheck(
{readerOutputLength:13, readerOutputRE:/.*/ , focusOnSuccess:null, onSuccess: null }
);
}
);
(Lasīt komentārus)
Nopūsties: