/**
* Copyright (c) 2013 Block Alexander
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*/
jQuery(document).ready(function ($) {
$("#upload").on("change", OnGetFile);
$("#drop").on("drop", OnGetFile);
function OnGetFile(e) {
$("#filename").html("get ready...");
e.stopPropagation();
e.preventDefault();
var file = null;
if (e.dataTransfer) { // file drag and drop
file = e.dataTransfer.files[0] || null;
} else if ($("#upload")[0].files) { // file upload
file = $("#upload")[0].files[0] || null;
}
if (!file) {
return;
}
var reader = new FileReader();
reader.readAsDataURL(file, "UTF-8");
reader.onload = function (e) {
$("#filename").html("Result: '" + file.name + "' (" + e.target.result.length + " B)");
$("#result").val(e.target.result);
$('#img').attr('src', $("#result").val());
};
reader.onerror = function (e) {
$("#result").val(e.target.error);
$('#img').attr('src', $("#result").val());
};
}
});
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.