3 // Check if window.FileReader exists to make
4 // sure the browser supports file uploads
5 if ( typeof(window.FileReader) ) {
6 var _dz = $('#photo_adh');
9 // Add a nice drag effect
10 _dz[0].ondragover = function() {
11 _dz.css({ opacity: 0.4 });
12 _dz.transition('pulsating');
16 // Remove the drag effect when leaving the dropping zone
17 _dz[0].ondragleave = function() {
18 _dz.css({ opacity: 1 });
19 _dz.transition('stop all');
23 // The drop event handles the file sending
24 _dz[0].ondrop = function(event) {
25 // Stop the browser from opening the file in the window
26 event.preventDefault();
27 _dz.css({ opacity: 1 });
28 _dz.transition('stop all');
29 $('.message').remove();
31 var file = event.dataTransfer.files[0];
33 {% if preferences.pref_force_picture_ratio == 1 %}
34 {% set system_ratio = (preferences.pref_member_picture_ratio == 'square_ratio') ? _T("Square (1:1)") : (preferences.pref_member_picture_ratio == 'portrait_ratio') ? _T("Portrait (3:4)") : (preferences.pref_member_picture_ratio == 'landscape_ratio') ? _T("Landscape (4:3)") %}
36 var cropping = { ratio: '{{ preferences.pref_member_picture_ratio }}' };
37 var focus_select = '<div class="ui basic horizontally fitted segment form"><div class="field">';
38 focus_select += '<select name="crop_focus_ajax" id="crop_focus_ajax" class="ui dropdown nochosen">';
39 focus_select += '<option value="center">{{ _T("Center") }}</option>';
40 focus_select += '<option value="top">{{ _T("Top") }}</option>';
41 focus_select += '<option value="bottom">{{ _T("Bottom") }}</option>';
42 focus_select += '<option value="left">{{ _T("Left") }}</option>';
43 focus_select += '<option value="right">{{ _T("Right") }}</option>';
44 focus_select += '</select>';
45 focus_select += '</div></div>';
47 {% include "elements/js/modal.js.twig" with {
48 modal_title_twig: _T("Cropping focus")|e("js"),
49 modal_content_twig: _T("Choose the area of the original image to preserve after cropping to the final ratio defined in the settings : %ratio")|replace({"%ratio": system_ratio})|e('js'),
51 modal_other_options: {
54 modal_onshow: "$(this).find('.content').append(focus_select);$('#crop_focus_ajax').dropdown();",
55 modal_onapprove: "cropping.focus=$(this).find('#crop_focus_ajax').val();_fileLoad(file, cropping);"
62 var _fileLoad = function(file, cropping_settings) {
63 var reader = new FileReader();
64 reader.readAsDataURL(file);
67 if (cropping_settings) {
68 var cropping = cropping_settings;
71 reader.onload = function(evt) {
75 url : '{{ url_for("photoDnd") }}',
77 member_id: {{ member.id }},
80 file: evt.target.result,
83 {% include "elements/js/loader.js.twig" with {
84 selector: '#member_card'
86 success: function(res){
87 window.location.reload(true);
90 {% include "elements/js/modal.js.twig" with {
91 modal_title_twig: _T("An error occurred sending photo :(")|e("js"),
92 modal_without_content: true,
94 modal_deny_only: true,
95 modal_cancel_text: _T("Close")|e("js"),
96 modal_classname: "redalert",