[jQuery] Wierd bug?

[jQuery] Wierd bug?

I found a bug in 216.
I am still using the ajaxForm functions created by Mark C, however,
using SVN 216, something changed so they don't work anymore.
I can't produce a test page at the moment, but i hope John knows what is
wrong.
Anyway here is the case
In the function " $.fn.ajaxForm " there is this code:
e.preventDefault();
$(this).ajaxSubmit(target, post_cb, pre_cb);
return false;
When i do an alert on "this" i get the form element. (this is correct)
Here is the wierd thing:
You can see it assigns a new custom function called " $.fn.ajaxSubmit "
to the form object which is called when the form is submitted.
When i do an alert on $(this) in that function (ajaxSubmit) i get the
fieldset, which is immediately after the form and not the form itself
although the form was used to bind the custom function... :(
So somehow the object get shifted...
Here is the form code i use (for convenience, the comments are stripped):
--------------------------------------------------
$.fn.ajaxSubmit = function(target, post_cb, pre_cb, url, mth) {
if ( !this.vars ) this.serialize();

if (pre_cb && pre_cb.constructor == Function)
if (pre_cb(this.vars) === false) return;
var url = url || f.action || '';
var mth = mth || f.method || 'POST';
if (target && target.constructor == Function) {
$.ajax(mth, url, $.param(this.vars), target);
} else if (target && target.constructor == String) {
$(target).load(url, this.vars, post_cb);
} else {
this.vars.push({name: 'evaljs', value: 1});
$.ajax(mth, url, $.param(this.vars), function(r) {
eval(r.responseText);
});
}
return this;
};
$.fn.ajaxForm = function(target, post_cb, pre_cb) {
return this.each(function(){
$('input[@type="submit"],input[@type="image"]',
this).click(function(ev){
this.form.clicked = this;
if (ev.offsetX != undefined) {
this.form.clicked_x = ev.offsetX;
this.form.clicked_y = ev.offsetY;
} else {
this.form.clicked_x = ev.pageX - this.offsetLeft;
this.form.clicked_y = ev.pageY - this.offsetTop;
}
});
})*.submit(function(e){
e.preventDefault();
$(this).ajaxSubmit(target, post_cb, pre_cb);
return false;
})*;
};
$.fn.formdata = function(){
this.serialize();
return this.vars;
};
$.fn.serialize = function() {
var a = [];
var ok = {INPUT:true, TEXTAREA:true, OPTION:true};
$('*', this).each(function() {
if (this.disabled || this.type == 'reset' ||
(this.type == 'checkbox' && !this.checked) ||
(this.type == 'radio' && !this.checked)) return;
if (this.type == 'submit' || this.type == 'image') {
if (this.form.clicked != this) return;
if (this.type == 'image') {
if (this.form.clicked_x) {
a.push({name: this.name+'_x', value:
this.form.clicked_x});
a.push({name: this.name+'_y', value:
this.form.clicked_y});
return;
}
}
}
if (!ok[this.nodeName.toUpperCase()])
return;
var par = this.parentNode;
var p = par.nodeName.toUpperCase();
if ((p == 'SELECT' || p == 'OPTGROUP') && !this.selected) return;
var n = this.name;
if (!n) n = (p == 'OPTGROUP') ? par.parentNode.name : (p ==
'SELECT') ? par.name : this.name;
if (n == undefined) return;
a.push({name: n, value: this.value});
});

this.vars = a;
return this;
};
--------------------------------------------------
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/