summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSarven Capadisli <csarven@status.net>2009-11-28 14:27:04 +0000
committerSarven Capadisli <csarven@status.net>2009-11-28 14:27:04 +0000
commitd5a92767916d5fcb3cc750e9ec55edc5c028e838 (patch)
treea7c19bd8c9c0a71a061d215407e2f41a35e3c7ef
parent4e55251c57de2fc8dda48fef5f4b941ac8baf1a7 (diff)
Bind submit to a form by SN.U.FormXHR() only once.
-rw-r--r--js/util.js55
1 files changed, 29 insertions, 26 deletions
diff --git a/js/util.js b/js/util.js
index f3b71cea8..f7f3d5e76 100644
--- a/js/util.js
+++ b/js/util.js
@@ -131,34 +131,37 @@ var SN = { // StatusNet
},
FormXHR: function(f) {
- f.bind('submit', function(e) {
- form_id = $(this)[0].id;
- $.ajax({
- type: 'POST',
- dataType: 'xml',
- url: $(this)[0].action,
- data: $(this).serialize() + '&ajax=1',
- beforeSend: function(xhr) {
- $('#'+form_id).addClass(SN.C.S.Processing);
- $('#'+form_id+' .submit').addClass(SN.C.S.Disabled);
- $('#'+form_id+' .submit').attr(SN.C.S.Disabled, SN.C.S.Disabled);
- },
- error: function (xhr, textStatus, errorThrown) {
- alert(errorThrown || textStatus);
- },
- success: function(data, textStatus) {
- if (typeof($('form', data)[0]) != 'undefined') {
- 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));
+ if (jQuery.data(f[0], "ElementData") === undefined) {
+ jQuery.data(f[0], "ElementData", {Bind:'submit'});
+ f.bind('submit', function(e) {
+ form_id = $(this)[0].id;
+ $.ajax({
+ type: 'POST',
+ dataType: 'xml',
+ url: $(this)[0].action,
+ data: $(this).serialize() + '&ajax=1',
+ beforeSend: function(xhr) {
+ $('#'+form_id).addClass(SN.C.S.Processing);
+ $('#'+form_id+' .submit').addClass(SN.C.S.Disabled);
+ $('#'+form_id+' .submit').attr(SN.C.S.Disabled, SN.C.S.Disabled);
+ },
+ error: function (xhr, textStatus, errorThrown) {
+ alert(errorThrown || textStatus);
+ },
+ success: function(data, textStatus) {
+ if (typeof($('form', data)[0]) != 'undefined') {
+ 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));
+ }
}
- }
+ });
+ return false;
});
- return false;
- });
+ }
},
FormNoticeXHR: function(form) {