form.js
41 lines
| 1.3 KiB
| application/javascript
|
JavascriptLexer
|
r698 | var isCompact = false; | ||
|
r673 | |||
|
r680 | $('input[name=image]').wrap($('<div class="file_wrap"></div>')); | ||
|
r676 | |||
$('body').on('change', 'input[name=image]', function(event) { | ||||
|
r673 | var file = event.target.files[0]; | ||
if(file.type.match('image.*')) { | ||||
var fileReader = new FileReader(); | ||||
fileReader.addEventListener("load", function(event) { | ||||
|
r680 | var wrapper = $('.file_wrap'); | ||
wrapper.find('.file-thumb').remove(); | ||||
wrapper.append( | ||||
$('<div class="file-thumb" style="background-image: url('+event.target.result+')"></div>') | ||||
|
r673 | ); | ||
}); | ||||
fileReader.readAsDataURL(file); | ||||
} | ||||
}); | ||||
|
r676 | |||
var fullForm = $('.swappable-form-full'); | ||||
function swapForm() { | ||||
if (isCompact) { | ||||
|
r698 | // TODO Use IDs (change the django form code) instead of absolute numbers | ||
fullForm.find('textarea').appendTo(fullForm.find('.form-row')[4]); | ||||
fullForm.find('.file_wrap').appendTo(fullForm.find('.form-row')[7]); | ||||
fullForm.find('.form-row').show(); | ||||
|
r703 | |||
scrollToBottom(); | ||||
|
r676 | } else { | ||
|
r698 | fullForm.find('textarea').appendTo($('.compact-form-text')); | ||
fullForm.find('.file_wrap').insertBefore($('.compact-form-text')); | ||||
fullForm.find('.form-row').hide(); | ||||
fullForm.find('input[type=text]').val(''); | ||||
|
r676 | } | ||
isCompact = !isCompact; | ||||
} | ||||