var ITEM_FILE_SOURCE = 'fileSource'; $('input[name=image]').wrap($('
')); $('body').on('change', 'input[name=image]', function(event) { var file = event.target.files[0]; if(file.type.match('image.*')) { var fileReader = new FileReader(); fileReader.addEventListener("load", function(event) { var wrapper = $('.file_wrap'); wrapper.find('.file-thumb').remove(); wrapper.append( $('') ); }); fileReader.readAsDataURL(file); } }); var form = $('#form'); $('textarea').keypress(function(event) { if ((event.which == 10 || event.which == 13) && event.ctrlKey) { form.find('input[type=submit]').click(); } }); $('#preview-button').click(function() { var data = { raw_text: $('textarea').val() } var diffUrl = '/api/preview/'; $.post(diffUrl, data, function(data) { var previewTextBlock = $('#preview-text'); previewTextBlock.html(data); previewTextBlock.show(); }) }); /** * Show text in the errors row of the form. * @param form * @param text */ function showAsErrors(form, text) { form.children('.form-errors').remove(); if (text.length > 0) { var errorList = $('