sutty/app/assets/javascripts/image_preview.js

12 lines
338 B
JavaScript
Raw Normal View History

2019-08-22 01:09:29 +00:00
$(document).on('turbolinks:load', function() {
$('input[type=file]').on('change', function(event) {
if (event.target.files.length == 0) return;
var input = $(event.target);
var preview = $(`#${input.data('preview')}`);
preview.attr('src',
window.URL.createObjectURL(event.target.files[0]));
});
});