/* Papermill SWFUpload wrapper You'll need jQuery or a **very** little bit of rewriting for native/prototype */ notify = function(message, type) { // wrap with your own javascript alert system (here is the thing for jGrowl) //if(type == "notice") { jQuery.noticeAdd({ text: message, stayTime: 4000, stay: false, type: type }) } //if(type == "warning") { jQuery.noticeAdd({ text: message, stayTime: 9000, stay: false, type: type }) } //if(type == "error") { jQuery.noticeAdd({ text: message, stayTime: 20000, stay: false, type: type }) } // or simply alert(type + ": " + message) } var Upload = { // The total number of files queued with SWFUpload files_queued: 0, set_recipient_id: function(dom_id) { this.recipient_id = dom_id }, file_dialog_complete: function(num_selected, num_queued) { // SwfUpload doesn't order uploads by name out of the box... this.sorted_queue = []; this.index = 0; if (num_queued > 0) { file_queue = []; global_index = 0; index = 0; do { file = this.callFlash("GetFileByIndex", [global_index]); if(file != null && file.filestatus == -1) { file_queue[index] = file; index++; } global_index++; } while (file != null); this.sorted_queue = file_queue.sort(function(a,b){ if(b.name < a.name){return (1)} }) self = this; jQuery(this.sorted_queue).each( function(index, file) { li = jQuery('
  • ').attr({ 'id': file.id, 'class': 'swfupload' }); li.append(jQuery('').attr('class', 'name').html(file.name.substring(0, 10) + '...')); li.append(jQuery('').attr('class', 'status').html(SWFUPLOAD_PENDING)); li.append(jQuery('').attr('class', 'progress').append('')); if(self.settings.file_queue_limit == 1) { jQuery("#" + self.settings.upload_id).html(li); } else { jQuery("#" + self.settings.upload_id).append(li); } }) this.startUpload(this.sorted_queue[this.index++].id); } }, upload_start: function(file) { jQuery('#' + file.id + ' .status').html(SWFUPLOAD_LOADING); }, upload_progress: function(file, bytes, total) { percent = Math.ceil((bytes / total) * 100); jQuery('#' + file.id + ' .progress span').width(percent + '%'); }, upload_error: function(file, code, message) { notify(SWFUPLOAD_ERROR + " " + file.name + " (" + message + " [" + code + "])", "error"); jQuery('#' + file.id).remove(); }, upload_success: function(file, data) { jQuery('#' + file.id).replaceWith(jQuery(data)); }, upload_complete: function(file) { Upload.files_queued -= 1; if(this.sorted_queue[this.index]) { this.startUpload(this.sorted_queue[this.index++].id) } }, file_queue_error: function(file, error_code, message) { upload_error(file, error_code, message) } }