document.addEventListener('DOMContentLoaded', function () {
var frameFile;
var clearInputDownload = function () {
frameFile.querySelector('.output-image').remove();
frameFile.querySelector('.output').classList.remove('full');
frameFile.querySelector('input').value = '';
};
var handleFileSelect = function (evt) {
var file = evt.target.files; // FileList object
frameFile = evt.target.parentNode;
var f = file[0];
// Only process image files.
// if (!f.type.match('image.*')) {
// alert("Только изображения");
// }
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function (theFile) {
return function (e) {
// Render thumbnail.
var div = document.createElement('div');
div.classList.add('output-image');
div.innerHTML = ['<img class="thumb" title="', escape(theFile.name), '" src="', e.target.result, '" /><span class="output-delete" tabindex=0>delete</span>'].join('');
frameFile.querySelector('.output').insertBefore(div, null);
frameFile.querySelector('.output').classList.add('full');
frameFile.querySelector('.output-delete').addEventListener('click', clearInputDownload, false);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
};
var downloadImageBlocks = document.querySelectorAll('.download-image input');
for (var i = 0; i < downloadImageBlocks.length; i++) {
downloadImageBlocks[i].addEventListener('change', handleFileSelect, false);
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.