i haven't had anything to do with jquery so far. as much as i've dug
through the forums and docs, it does not support anything similar to
mootools class syntax, right? i've made a simple and reusable class in
mootools, the i need to re-make in jquery. can anybody helm me with
this?

in short - it checks an input field for a specifig string and extracts
a number out of it and puts it back into the input field. this is used
with usb card readers.

here's the instantiation (inside another class):
new CardInputCheck($('card_num_input'), { onSuccess:
this.validateAndSubmit.bind(this) });


here's the class:
var CardInputCheck = new Class({

        Implements: [ Options, Events ],

        element: null,
        options: {
                readerOutputLength: 117,        // length of the card input
                readerOutputRE: /^\%B\d{16}\^\s+\^\d+\?;\d+=\d+\?$/,  // regexp 
for
the card input

                focusOnSuccess: null,   // element to focus on success
                onSuccess: $empty       // function to execute on success
        },

        initialize: function(inputFieldElement, options) {
                this.setOptions(options);
                this.element = $(inputFieldElement);
                if(this.element && $type(this.element) == 'element') {
                        this.element.addEvent('keyup', 
this.elementOnKeyPress.bindWithEvent
(this));
                        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
                }
        },

        elementOnKeyPress: function(event) {
                var v = this.element.get('value').trim();
                if(v.length == this.options.readerOutputLength && v.test
(this.options.readerOutputRE)) {
                        this.element.set('value', v.substr(8, 10));
                        this.success();
                }
        },

        success: function() {
                if(this.options.focusOnSuccess && 
this.options.focusOnSuccess.focus)
{
                        try {
                                this.options.focusOnSuccess.focus();
                        } catch(e) {
                        }
                }

                this.fireEvent('success');
        },

        focusElement: function() {
                try {
                        // focus method sometimes throw errors...
                        this.element.focus();
                } catch(e) {
                }
        }

});


will terribly appreciate any solution!
respect

Reply via email to