Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

blueimp jQuery file upload new files order

i'm trying to find place inside blueimp file upload scripts to change the behavior of new files position in the table. How to force them to by added at the top of the table insted of the end of files list?

like image 369
zibra Avatar asked Dec 24 '14 12:12

zibra


2 Answers

Just add the property prependFiles:true

Example:

$('.fileupload').fileupload({
    url: 'your_url',
    dataType: 'json',
    prependFiles:true
});
like image 76
André Secco Avatar answered Nov 17 '22 22:11

André Secco


I did it by overwriting the event listener for fileuploaddone and adding prepend instead of append.

It look like this

$('.fileupload').fileupload({
        url: 'phpUpload/index.php?customDir='+saveFolder,
        dataType: 'json',
        dropZone: $(this),
        autoUpload: true,
        acceptFileTypes: /(\.|\/)(gif|jpe?g|png|pdf|mp3|mp4|wav|doc|docx|ppt)$/i,
        maxFileSize: 150000000, // 150 MB
        // Enable image resizing, except for Android and Opera,
        // which actually support image resizing, but fail to
        // send Blob objects via XHR requests:
        disableImageResize: /Android(?!.*Chrome)|Opera/
            .test(window.navigator.userAgent),
        previewMaxWidth: 100,
        previewMaxHeight: 100,
        previewCrop: true
    }).on('fileuploadadd', function (e, data) {
        // you can leave this out if you want the default design
        data.context = $('<div/>').addClass('existingMediaFile');
        $.each(data.files, function (index, file) {
            var node = $('<a/>').append($('<span/>').text(file.name));
            node.appendTo(data.context);
        });

    }).on('fileuploaddone', function (e, data) {
        $.each(data.result.files, function (index, file) {
            $(data.context.children()[index]).prepend(file.name+' '+file.thumbnailUrl);
        });
    })
like image 1
Lau Avatar answered Nov 17 '22 21:11

Lau