$(function () { // Add a flash message var flash = function (category, message) { $('#flashes').append($('
Waiting for data to finish traversing Tor network ...');
}
}, false);
ajax.addEventListener('load', function (event) {
// Remove the upload div
ajax.$upload_div.remove();
// Parse response
try {
var response = JSON.parse(ajax.response);
// The 'new_body' response replaces the whole HTML document and ends
if ('new_body' in response) {
$('body').html(response['new_body']);
return;
}
// Show error flashes
if ('error_flashes' in response) {
for (var i = 0; i < response['error_flashes'].length; i++) {
flash('error', response['error_flashes'][i]);
}
}
// Show info flashes
if ('info_flashes' in response) {
for (var i = 0; i < response['info_flashes'].length; i++) {
flash('info', response['info_flashes'][i]);
}
}
} catch (e) {
flash('error', 'Invalid response from server: ' + data);
}
}, false);
ajax.addEventListener('error', function (event) {
flash('error', 'Error uploading: ' + filenames.join(', '));
// Remove the upload div
ajax.$upload_div.remove()
}, false);
ajax.addEventListener('abort', function (event) {
flash('error', 'Upload aborted: ' + filenames.join(', '));
}, false);
// Make the upload div
/* The DOM for an upload looks something like this: