2015-08-06 2 views
1

Я использую этот плагин jquery https://formstone.it/components/upload/, и все работает отлично, но ... имеет возможность ограничить максимальный файл и не работает, называется «maxQueue».Formstone upload maxQueue не работает

Мой код заключается в следующем:

var $filequeue, 
    $filelist; 

    $filequeue = $(".filelist.queue"); 
    $filelist = $(".filelist.complete"); 

    $(".upload").upload({ 
     label: "SUELTA AQUI", 
     maxQueue: 1, 
    }).on("start.upload", onStart) 
     .on("complete.upload", onComplete) 
     .on("filestart.upload", onFileStart) 
     .on("fileprogress.upload", onFileProgress) 
     .on("filecomplete.upload", onFileComplete) 
     .on("fileerror.upload", onFileError); 

function onStart(e, files) { 
    console.log("Start"); 
    var html = ''; 
    for (var i = 0; i < files.length; i++) { 
     html += '<li data-index="' + files[i].index + '"><span class="file">' + files[i].name + '</span><span class="progress">Cola</span></li>'; 
    } 
    $filequeue.append(html); 
} 

function onComplete(e) { 
    console.log("Complete"); 
    // All done! 
} 

function onFileStart(e, file) { 
    console.log("File Start"); 
    $filequeue.find("li[data-index=" + file.index + "]") 
       .find(".progress").text("0%"); 
} 

function onFileProgress(e, file, percent) { 
    console.log("File Progress"); 
    $filequeue.find("li[data-index=" + file.index + "]") 
       .find(".progress").text(percent + "%"); 
} 

function onFileComplete(e, file, response) { 
    console.log("File Complete"); 
    if (response.trim() === "" || response.toLowerCase().indexOf("error") > -1) { 
     $filequeue.find("li[data-index=" + file.index + "]").addClass("errorb") 
        .find(".progress").text(response.trim()); 
    } else { 
     var $target = $filequeue.find("li[data-index=" + file.index + "]"); 
     $target.find(".file").text(file.name); 
     $target.find(".progress").remove(); 
     $target.appendTo($filelist); 
     console.log(response); 
    } 
} 

function onFileError(e, file, error) { 
    console.log("File Error"); 
    $filequeue.find("li[data-index=" + file.index + "]").addClass("errorb") 
       .find(".progress").text("Error: " + error); 
} 

          <div class="upload target" data-upload-options='{"action":"<?php echo get_template_directory_uri().'/inc/upload.php'; ?>", "maxSize": "1048576", "maxQueue": "1"}'></div> 

Все отлично работает, но нет никаких ограничений, позволяет загружать 1, 10, 100 или все, что вы хотите.

Что может быть неправильным?

ответ

0

Параметр maxQueue определяет, сколько файлов должно быть загружено параллельно, а не общее количество файлов, которые могут быть загружены в целом. Вы заметите, что с maxQueue, установленным в 1, одновременно появляется только одна загрузка. Плагин будет ждать завершения первого завершения, прежде чем начать следующую передачу.

Смежные вопросы