Created
October 18, 2015 12:34
-
-
Save mnsmarcelo/4c2149289e00769ec9be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function readFile(file, callback) { | |
var reader = new FileReader(); | |
reader.onload = callback | |
reader.readAsDataURL(file); | |
} | |
document.getElementsByClassName("arquivos")[0].addEventListener("change", function () { | |
document.getElementsByClassName("miniaturas")[0].innerHTML = ""; | |
document.getElementsByClassName("alert-danger")[0].style.display = "none"; | |
document.getElementsByClassName("alert-success")[0].style.display = "none"; | |
var arquivos = document.getElementsByClassName("arquivos")[0].files; | |
for (var i = 0; i < arquivos.length; i++) { | |
//verifica se é uma imagem | |
if (arquivos[i].type.match('image.*')) { | |
readFile(arquivos[i], function (e) { | |
document.getElementsByClassName("miniaturas")[0].insertAdjacentHTML('beforeend', '<div class="col-xs-6 col-md-3"><a href="#" class="thumbnail"><img src="' + e.target.result + '" ></a></div>'); | |
}); | |
} else { | |
document.getElementsByClassName("miniaturas")[0].insertAdjacentHTML('beforeend', '<div class="col-xs-6 col-md-3"><a href="#" class="thumbnail"><img src="doc-128.png" ></a></div>'); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment