1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-29 09:44:28 +01:00
This commit is contained in:
Michael Foster 2013-09-15 14:54:18 +10:00
parent bc41892255
commit d27a7cb6c3

View File

@ -12,15 +12,20 @@
*/ */
$(window).ready(function() { $(window).ready(function() {
var do_not_ajax = false;
var setup_form = function($form) { var setup_form = function($form) {
$form.submit(function() { $form.submit(function() {
if (do_not_ajax)
return true;
var form = this; var form = this;
var submit_txt = $(this).find('input[type="submit"]').val(); var submit_txt = $(this).find('input[type="submit"]').val();
if (typeof FormData == 'undefined') if (window.FormData === undefined)
return true; return true;
var formData = new FormData(this); var formData = new FormData(this);
formData.append('json_response', '1'); formData.append('json_response', '1');
formData.append('post', $(this).find('input[type="submit"]').val());
var updateProgress = function(e) { var updateProgress = function(e) {
$(form).find('input[type="submit"]').val(_('Posting... (#%)').replace('#', Math.round(e.position / e.total * 100))); $(form).find('input[type="submit"]').val(_('Posting... (#%)').replace('#', Math.round(e.position / e.total * 100)));
@ -78,7 +83,16 @@ $(window).ready(function() {
error: function(xhr, status, er) { error: function(xhr, status, er) {
// An error occured // An error occured
// TODO // TODO
alert('Something went wrong!'); do_not_ajax = true;
$(form).find('input[type="submit"]').each(function() {
var $replacement = $('<input type="hidden">');
$replacement.attr('name', $(this).attr('name'));
$replacement.val(submit_txt);
$(this)
.after($replacement)
.replaceWith($('<input type="button">').val(submit_txt));
});
$(form).submit();
}, },
// Form data // Form data
data: formData, data: formData,
@ -94,7 +108,7 @@ $(window).ready(function() {
}); });
}; };
setup_form($('form[name="post"]')); setup_form($('form[name="post"]'));
$(window).on('quick-reply', function(e, quickForm) { $(window).on('quick-reply', function() {
setup_form($('form#quick-reply')); setup_form($('form#quick-reply'));
}); });
}); });