form.js
45 lines
| 1.2 KiB
| application/javascript
|
JavascriptLexer
neko259
|
r676 | var isCompact = true; | ||
neko259
|
r673 | |||
neko259
|
r680 | $('input[name=image]').wrap($('<div class="file_wrap"></div>')); | ||
neko259
|
r676 | |||
$('body').on('change', 'input[name=image]', function(event) { | ||||
neko259
|
r673 | var file = event.target.files[0]; | ||
if(file.type.match('image.*')) { | ||||
var fileReader = new FileReader(); | ||||
fileReader.addEventListener("load", function(event) { | ||||
neko259
|
r680 | var wrapper = $('.file_wrap'); | ||
wrapper.find('.file-thumb').remove(); | ||||
wrapper.append( | ||||
$('<div class="file-thumb" style="background-image: url('+event.target.result+')"></div>') | ||||
neko259
|
r673 | ); | ||
}); | ||||
fileReader.readAsDataURL(file); | ||||
} | ||||
}); | ||||
neko259
|
r676 | |||
var compactForm = $('.swappable-form-compact'); | ||||
var fullForm = $('.swappable-form-full'); | ||||
function swapForm() { | ||||
compactForm.toggle(); | ||||
fullForm.toggle(); | ||||
if (isCompact) { | ||||
var oldText = compactForm.find('textarea')[0].value; | ||||
fullForm.find('textarea')[0].value = oldText; | ||||
} else { | ||||
var oldText = fullForm.find('textarea')[0].value; | ||||
compactForm.find('textarea')[0].value = oldText; | ||||
} | ||||
isCompact = !isCompact; | ||||
neko259
|
r686 | |||
scrollToBottom(); | ||||
neko259
|
r676 | } | ||
if (compactForm.length > 0) { | ||||
fullForm.toggle(); | ||||
neko259
|
r686 | } | ||