Bind submit to a form by SN.U.FormXHR() only once.

This commit is contained in:
Sarven Capadisli 2009-11-28 14:27:04 +00:00
parent 4e55251c57
commit d5a9276791

View File

@ -131,34 +131,37 @@ var SN = { // StatusNet
}, },
FormXHR: function(f) { FormXHR: function(f) {
f.bind('submit', function(e) { if (jQuery.data(f[0], "ElementData") === undefined) {
form_id = $(this)[0].id; jQuery.data(f[0], "ElementData", {Bind:'submit'});
$.ajax({ f.bind('submit', function(e) {
type: 'POST', form_id = $(this)[0].id;
dataType: 'xml', $.ajax({
url: $(this)[0].action, type: 'POST',
data: $(this).serialize() + '&ajax=1', dataType: 'xml',
beforeSend: function(xhr) { url: $(this)[0].action,
$('#'+form_id).addClass(SN.C.S.Processing); data: $(this).serialize() + '&ajax=1',
$('#'+form_id+' .submit').addClass(SN.C.S.Disabled); beforeSend: function(xhr) {
$('#'+form_id+' .submit').attr(SN.C.S.Disabled, SN.C.S.Disabled); $('#'+form_id).addClass(SN.C.S.Processing);
}, $('#'+form_id+' .submit').addClass(SN.C.S.Disabled);
error: function (xhr, textStatus, errorThrown) { $('#'+form_id+' .submit').attr(SN.C.S.Disabled, SN.C.S.Disabled);
alert(errorThrown || textStatus); },
}, error: function (xhr, textStatus, errorThrown) {
success: function(data, textStatus) { alert(errorThrown || textStatus);
if (typeof($('form', data)[0]) != 'undefined') { },
form_new = document._importNode($('form', data)[0], true); success: function(data, textStatus) {
$('#'+form_id).replaceWith(form_new); if (typeof($('form', data)[0]) != 'undefined') {
$('#'+form_new.id).each(function() { SN.U.FormXHR($(this)); }); form_new = document._importNode($('form', data)[0], true);
$('#'+form_id).replaceWith(form_new);
$('#'+form_new.id).each(function() { SN.U.FormXHR($(this)); });
}
else {
$('#'+form_id).replaceWith(document._importNode($('p', data)[0], true));
}
} }
else { });
$('#'+form_id).replaceWith(document._importNode($('p', data)[0], true)); return false;
}
}
}); });
return false; }
});
}, },
FormNoticeXHR: function(form) { FormNoticeXHR: function(form) {