[jQuery] binding
[jQuery] binding
I'm trying to bind the event focus to my onfocus but the "this" is
conflicting with each other. Is the any alternative way of doing this?
Any ideas how i should do?
The script
$(document).ready(function() {
$("input").searchProducts();
});
(function($) {
$.fn.extend({
searchProducts: function () {
new $.searchProducts(this);
}
});
$.searchProducts = function(obj, options){
this.obj = obj;
obj.focus(this.onfocus);
// .blur(this.onblur)
// .keyup(this.onkeyup)
// .keydown(this.onkeydown)
// .keypress(this.onkeypress);
this.focused = false;
}
$.searchProducts.prototype = {
onfocus: function(event) {
this.focused = true;
console.debug(this);
},
onblur: function() {
console.debug("blur");
},
onkeyup: function(event) {
switch (event.keyCode) {
case 27: // escape
console.debug("escape");
break;
};
},
onkeydown: function() {
console.debug("keydown");
},
onkeypress: function(event) {
console.debug("keypress");
}
};
})(jQuery);