Как вызвать функцию после того, как все изображения в очереди загружены в swfupload

Я использую этот код и хочу вызвать функцию после загрузки всех изображений в очереди.


$(function(){
    $('#swfupload-control').swfupload({
        upload_url: "upload.php",
        file_post_name: 'uploadfile',
        file_size_limit : "20000",
        file_types : "*.jpg;*.png;*.gif",
        file_types_description : "Image files",
        file_upload_limit :500,
        flash_url : "js/swfupload/swfupload.swf",
        button_image_url : 'js/swfupload/wdp_buttons_upload_114x29.png',
        button_width : 114,
        button_height : 29,
        button_placeholder : $('#button')[0],
        debug: false
    })
        .bind('fileQueued', function(event, file){
            var listitem=''+
                'File: '+file.name+' ('+Math.round(file.size/20000)+' KB) '+
                ''+
                'Pending

'+ ' '+ ''; $('#log').append(listitem); $('li#'+file.id+' .cancel').bind('click', function(){ var swfu = $.swfupload.getInstance('#swfupload-control'); swfu.cancelUpload(file.id); $('li#'+file.id).slideUp('fast'); }); // start the upload since it's queued $(this).swfupload('startUpload'); }) .bind('fileQueueError', function(event, file, errorCode, message){ alert('Size of the file '+file.name+' is greater than limit'); }) .bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){ $('#queuestatus').text('Files Selected: '+numFilesSelected+' / Queued Files: '+numFilesQueued); }) .bind('uploadStart', function(event, file){ $('#log li#'+file.id).find('p.status').text('Uploading...'); $('#log li#'+file.id).find('span.progressvalue').text('0%'); $('#log li#'+file.id).find('span.cancel').hide(); }) .bind('uploadProgress', function(event, file, bytesLoaded){ //Show Progress var percentage=Math.round((bytesLoaded/file.size)*100); $('#log li#'+file.id).find('div.progress').css('width', percentage+'%'); $('#log li#'+file.id).find('span.progressvalue').text(percentage+'%'); }) .bind('uploadSuccess', function(event, file, serverData){ var item=$('#log li#'+file.id); item.find('div.progress').css('width', '100%'); item.find('span.progressvalue').text('100%'); var pathtofile='/'+file.name+'" target="_blank" >view »'; item.addClass('success').find('p.status').html(''); }) .bind('uploadComplete', function(event, file){ // upload has completed, try the next one in the queue $(this).swfupload('startUpload'); }) });

person Ravinder Singh    schedule 01.07.2011    source источник


Ответы (3)


Я бы предложил использовать такой плагин, как uplodify.

Он обеспечивает функцию обратного вызова после загрузки одного или нескольких изображений. Вы можете найти соответствующие примеры в их документации.

person topless    schedule 01.07.2011
comment
похоже, что его загрузчик тоже - person Andy; 01.07.2011
comment
@ Энди, вы, наверное, пишете, я на работе, поэтому я не просматривал код :) просто поделился своим подходом к проблеме. - person topless; 01.07.2011

получите количество файлов, которые вы загружаете, и в обработчике событий uploadComplete отслеживайте, сколько раз он вызывается, и проверяйте, равно ли оно количеству.

person Andy    schedule 01.07.2011

добавить обработчик:

upload_complete_handler     : uploadComplete

а в handlers.js в конце функции добавьте понравившийся код:

function uploadComplete(file) {
    try {
        /*  I want the next upload to continue automatically so I'll call startUpload here */
        if (this.getStats().files_queued === 0) {
            document.getElementById(this.customSettings.cancelButtonId).disabled = true;
        } else {    
            this.startUpload();
        }
    } catch (ex) {
        this.debug(ex);
    }

    // do what you want HERE!
}
person Ēriks Daliba    schedule 01.07.2011