##// END OF EJS Templates
Added image preview in the forms
neko259 -
r673:7eec232c default
parent child Browse files
Show More
@@ -0,0 +1,22 b''
1 $('#id_image').parent().append(
2 $('<div/>', {
3 id: 'file_wrap'
4 }).append($('#id_image'))
5 );
6
7 $('body').on('change', '#id_image', function(event) {
8 var file = event.target.files[0];
9
10 if(file.type.match('image.*')) {
11 var fileReader = new FileReader();
12
13 fileReader.addEventListener("load", function(event) {
14 $('#file_wrap').find('#file-thumb').remove();
15 $('#file_wrap').append(
16 $('<div id="file-thumb" style="background-image: url('+event.target.result+')"></div>')
17 );
18 });
19
20 fileReader.readAsDataURL(file);
21 }
22 });
@@ -36,3 +36,26 b''
36 display: none;
36 display: none;
37 }
37 }
38 }
38 }
39
40 #id_image {
41 display: block;
42 width: 100px;
43 height: 100px;
44 cursor: pointer;
45 position: absolute;
46 opacity: 0;
47 z-index: 1;
48 }
49
50 #file_wrap {
51 width: 100px;
52 height: 100px;
53 border: solid 1px white;
54 }
55
56 #file-thumb {
57 width: 100px;
58 height: 100px;
59 background-size: cover;
60 background-position: center;
61 }
@@ -217,6 +217,7 b' function resetForm(form) {'
217 form.find('input:text, input:password, input:file, select, textarea').val('');
217 form.find('input:text, input:password, input:file, select, textarea').val('');
218 form.find('input:radio, input:checkbox')
218 form.find('input:radio, input:checkbox')
219 .removeAttr('checked').removeAttr('selected');
219 .removeAttr('checked').removeAttr('selected');
220 $('#file_wrap').find('#file-thumb').remove();
220 }
221 }
221
222
222
223
@@ -144,6 +144,8 b''
144 </div>
144 </div>
145 </div>
145 </div>
146
146
147 <script src="{% static 'js/form.js' %}"></script>
148
147 {% endblock %}
149 {% endblock %}
148
150
149 {% block metapanel %}
151 {% block metapanel %}
@@ -67,6 +67,7 b''
67 <script src="{% static 'js/thread_update.js' %}"></script>
67 <script src="{% static 'js/thread_update.js' %}"></script>
68 {% endif %}
68 {% endif %}
69
69
70 <script src="{% static 'js/form.js' %}"></script>
70 <script src="{% static 'js/thread.js' %}"></script>
71 <script src="{% static 'js/thread.js' %}"></script>
71
72
72 {% endcache %}
73 {% endcache %}
General Comments 0
You need to be logged in to leave comments. Login now