Skip to content

Instantly share code, notes, and snippets.

@noomz
Created October 27, 2010 10:06
Show Gist options
  • Save noomz/648773 to your computer and use it in GitHub Desktop.
Save noomz/648773 to your computer and use it in GitHub Desktop.
function state_set(state) {
var form = $('#panda-ajax-uploader');
var file = $('#panda-upload-file');
var button = $('#panda-upload-button');
var box = $('#panda-progress-box');
var bar = $('#panda-progress-bar');
var status = $('#panda-progress-status');
$('#panda-progress-box').removeClass();
switch (state) {
case 'begin':
file.show();
button.attr('disabled', 'disabled').show();
box.hide();
var msg = '<p>Please choose a file to upload.</p>';
if (options.allowed_filetype != '*') {
msg += '<p>Allowed filetype are <em>' +
options.allowed_filetype.join(', ') +
'</em></p>';
}
statusSet('status', msg);
break;
case 'start_upload':
file.hide();
button.hide();
box.show();
statusSet('status', 'Uploading: 0%');
break;
case 'upload_success':
clearInterval(window.pandaTimer);
barWidth('100%');
file.hide();
button.hide();
statusSet('status', 'Uploaded <em>' + $('#panda-upload-file').val() + '</em> success.');
var filename = file.val();
try {
file.remove();
options.upload_success(id, filename);
}
catch (err) {
// Nothing
}
break;
case 'upload_error':
clearInterval(window.pandaTimer);
state_set('begin');
statusSet('error', 'Something error, Please try again.');
break;
default:
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment