$("head").append(''); function numerar_indice_arquivo(elemento) { if (elemento.attr("numerar_arquivos") == "sim") { var i = 1; $("#" + elemento.attr("destino")).find(".indice_arquivo").each( function() { $(this).html(i + ". "); i++; } ); } } $(document).ready(function() { $(".sistema_upload_arquivo").each( function() { var elemento = $(this); var objeto = new Array(); $("#" + elemento.attr("destino")).on( "click", ".remover_arquivo", function() { $(this).parent().remove(); numerar_indice_arquivo(elemento); } ); function enviar_arquivo() { if ( (typeof jQuery.grep(objeto,function(que){return !que[2];})[0] !== "undefined") && (elemento.attr("qntd_uploads_simultaneos") > 0) ) { for (var i=0;i 20) { data["nome_arquivo"] = data["nome_arquivo"].replace(new RegExp("([^/]*)\\..*$","g"),"$1").substr(0,20).replace(new RegExp(" *$"),"") + "..." + data["nome_arquivo"].replace(new RegExp("^.*\\.","g"),""); } $("#" + elemento.attr("destino")).find("#arquivo_" + objeto[indice_objeto_atual][0]).html('' + data["nome_arquivo"] + ' [remover]'); } else if (typeof data[0]["erro"] !== "undefined") { $("#" + elemento.attr("destino")).find("#arquivo_" + objeto[indice_objeto_atual][0]).find(".progresso_arquivo").html("-%"); $("#" + elemento.attr("destino")).find("#arquivo_" + objeto[indice_objeto_atual][0]).find(".cancelar_envio_arquivo").off("click","").css("cursor","pointer").html("ERRO").on( "click", function() { alert(data[0]["erro"]); } ); alert(data[0]["erro"]); } numerar_indice_arquivo(elemento); } else{ if (objeto[indice_objeto_atual][3].status == "FALHA_NA_CONEXAO_QUE_NAO_TENHA_SIDO_ABORTADA_PELO_USUARIO") { /* $("#" + elemento.attr("destino")).find("#arquivo_" + objeto[indice_objeto_atual][0]).find(".cancelar_envio_arquivo").off("click","").css("cursor","default").html("FALHA NA CONEXÃO"); $("#" + elemento.attr("destino")).find("#arquivo_" + objeto[indice_objeto_atual][0]).find(".progresso_arquivo").html("-%"); */ } else if (objeto[indice_objeto_atual][3].status == "0") { $("#" + elemento.attr("destino")).find("#arquivo_" + objeto[indice_objeto_atual][0]).remove(); } } elemento.attr("qntd_uploads_simultaneos",parseInt(elemento.attr("qntd_uploads_simultaneos")) + 1); $("#" + elemento.attr("destino")).find("#arquivo_" + objeto[indice_objeto_atual][0]).removeClass("arquivo_ainda_nao_enviado").addClass("arquivo_enviado_sucesso"); if (elemento.is("[executar_apos_finalizar_envio_arquivo]")) { eval(elemento.attr("executar_apos_finalizar_envio_arquivo")); } enviar_arquivo(); } }; objeto[indice_objeto_atual][3].upload.onprogress = function(e) { if ( (e.lengthComputable) && (e.total > 0) && ($("#" + elemento.attr("destino")).find("#arquivo_" + objeto[indice_objeto_atual][0]).find(".progresso_arquivo").html() != "-%") ) { $("#" + elemento.attr("destino")).find("#arquivo_" + objeto[indice_objeto_atual][0]).find(".progresso_arquivo").html(Math.round(100*e.loaded/e.total) + "%"); } } objeto[indice_objeto_atual][3].open("POST",elemento.attr("action"),true); objeto[indice_objeto_atual][3].send(conteudo_arquivo); } } } function verificar_arquivo(arquivo) { var informacoes_sobre_arquivo = new Array(); for (i=0;i 20) { nome_arquivo = objeto[objeto.length - 1][1].name.replace(new RegExp("([^/]*)\\..*$","g"),"$1").substr(0,20).replace(new RegExp(" *$"),"") + "..." + objeto[objeto.length - 1][1].name.replace(new RegExp("^.*\\.","g"),""); } $("#" + elemento.attr("destino")).append('
0% ' + nome_arquivo + ' [cancelar]
'); $("#" + elemento.attr("destino")).find("#arquivo_" + objeto[objeto.length - 1][0]).find(".cancelar_envio_arquivo").on( "click", function() { for (var i=0;i 1?'multiple=""':'') + ' style="display:none;" />').on( "change", function() { verificar_arquivo($(this).prop("files")); } ).appendTo(document.documentElement).trigger("click"); } ); $(this).on( "dragenter dragexit dragover drop", function(e) { e.stopPropagation(); e.preventDefault(); if (e.type == "drop") { verificar_arquivo(e.originalEvent.dataTransfer.files); } } ); } ); });