Sha256: 82e6b78723aa1b1513135f4b471f208916c16fc111f107c85d428d566ca6431c

Contents?: true

Size: 1.24 KB

Versions: 9

Compression:

Stored size: 1.24 KB

Contents

function progress_handling(e){
    if(e.lengthComputable){
        var prog = Math.round(e.loaded / e.total * 100);
        $('.progress-bar').css('width',prog.toString()+'%');
        $('#file_progress').html(prog.toString()+'%');
    }
}

function init_upload() {
    $('#new_document').on('submit', function (e) {
        e.preventDefault();
        formData = jQuery(this);
        var fileInput = document.getElementById('document_file');
        var file = fileInput.files[0];
        data = new FormData();
        data.append('authenticity_token', $('#authenticity_token').val())
        data.append('document[file]',file);
        $.ajax({
            url: formData.attr('action'),
            type: formData.attr('method'),
            processData: false,
            contentType: false,
            xhr: function() {
                $('#file_progress_bar').show();
                $('#file_progress_bar').removeClass('hidden');
                var myXhr = $.ajaxSettings.xhr();
                if(myXhr.upload){
                    myXhr.upload.addEventListener('progress',progress_handling, false);
                }
                return myXhr;
            },
            data: data
        });
    });
}

$(document).ready(function () {
    init_upload();
});

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
upload_documents_tool-0.1.8 app/assets/javascripts/progress_bar.js
upload_documents_tool-0.1.7 app/assets/javascripts/progress_bar.js
upload_documents_tool-0.1.6 app/assets/javascripts/progress_bar.js
upload_documents_tool-0.1.5 app/assets/javascripts/progress_bar.js
upload_documents_tool-0.1.4 app/assets/javascripts/progress_bar.js
upload_documents_tool-0.1.3 app/assets/javascripts/progress_bar.js
upload_documents_tool-0.1.2 app/assets/javascripts/progress_bar.js
upload_documents_tool-0.1.1 app/assets/javascripts/progress_bar.js
upload_documents_tool-0.1.0 app/assets/javascripts/progress_bar.js