Show More
@@ -1,41 +1,41 b'' | |||||
1 | var isCompact = false; |
|
1 | var isCompact = false; | |
2 |
|
2 | |||
3 | $('input[name=image]').wrap($('<div class="file_wrap"></div>')); |
|
3 | $('input[name=image]').wrap($('<div class="file_wrap"></div>')); | |
4 |
|
4 | |||
5 | $('body').on('change', 'input[name=image]', function(event) { |
|
5 | $('body').on('change', 'input[name=image]', function(event) { | |
6 | var file = event.target.files[0]; |
|
6 | var file = event.target.files[0]; | |
7 |
|
7 | |||
8 | if(file.type.match('image.*')) { |
|
8 | if(file.type.match('image.*')) { | |
9 | var fileReader = new FileReader(); |
|
9 | var fileReader = new FileReader(); | |
10 |
|
10 | |||
11 | fileReader.addEventListener("load", function(event) { |
|
11 | fileReader.addEventListener("load", function(event) { | |
12 | var wrapper = $('.file_wrap'); |
|
12 | var wrapper = $('.file_wrap'); | |
13 |
|
13 | |||
14 | wrapper.find('.file-thumb').remove(); |
|
14 | wrapper.find('.file-thumb').remove(); | |
15 | wrapper.append( |
|
15 | wrapper.append( | |
16 | $('<div class="file-thumb" style="background-image: url('+event.target.result+')"></div>') |
|
16 | $('<div class="file-thumb" style="background-image: url('+event.target.result+')"></div>') | |
17 | ); |
|
17 | ); | |
18 | }); |
|
18 | }); | |
19 |
|
19 | |||
20 | fileReader.readAsDataURL(file); |
|
20 | fileReader.readAsDataURL(file); | |
21 | } |
|
21 | } | |
22 | }); |
|
22 | }); | |
23 |
|
23 | |||
24 | var fullForm = $('.swappable-form-full'); |
|
24 | var fullForm = $('.swappable-form-full'); | |
25 |
|
25 | |||
26 | function swapForm() { |
|
26 | function swapForm() { | |
27 | if (isCompact) { |
|
27 | if (isCompact) { | |
28 | // TODO Use IDs (change the django form code) instead of absolute numbers |
|
28 | // TODO Use IDs (change the django form code) instead of absolute numbers | |
29 | fullForm.find('textarea').appendTo(fullForm.find('.form-row')[4]); |
|
29 | fullForm.find('textarea').appendTo(fullForm.find('.form-row')[4].children[0]); | |
30 | fullForm.find('.file_wrap').appendTo(fullForm.find('.form-row')[7]); |
|
30 | fullForm.find('.file_wrap').appendTo(fullForm.find('.form-row')[7].children[0]); | |
31 | fullForm.find('.form-row').show(); |
|
31 | fullForm.find('.form-row').show(); | |
32 |
|
32 | |||
33 | scrollToBottom(); |
|
33 | scrollToBottom(); | |
34 | } else { |
|
34 | } else { | |
35 | fullForm.find('textarea').appendTo($('.compact-form-text')); |
|
35 | fullForm.find('textarea').appendTo($('.compact-form-text')); | |
36 | fullForm.find('.file_wrap').insertBefore($('.compact-form-text')); |
|
36 | fullForm.find('.file_wrap').insertBefore($('.compact-form-text')); | |
37 | fullForm.find('.form-row').hide(); |
|
37 | fullForm.find('.form-row').hide(); | |
38 | fullForm.find('input[type=text]').val(''); |
|
38 | fullForm.find('input[type=text]').val(''); | |
39 | } |
|
39 | } | |
40 | isCompact = !isCompact; |
|
40 | isCompact = !isCompact; | |
41 | } |
|
41 | } |
General Comments 0
You need to be logged in to leave comments.
Login now