comparison static/js/markitup/sets/markdown/set.js @ 725:682b159f3763

On comment views, the photo uploading stuff won't be there. Fix javascript.
author Brian Neal <bgneal@gmail.com>
date Sat, 21 Sep 2013 21:18:40 -0500
parents 71d17d267e27
children 4f265f61874b
comparison
equal deleted inserted replaced
724:8b027e7a7977 725:682b159f3763
126 } 126 }
127 return false; 127 return false;
128 }); 128 });
129 129
130 var $photoProgress = $('#photo-upload-progress'); 130 var $photoProgress = $('#photo-upload-progress');
131 var $photoForm = $('#photo-upload-form'); 131 if ($photoProgress.length) {
132 var $postBox = $('#id_body'); 132 var $photoForm = $('#photo-upload-form');
133 var $photoUploadSubmit = $('#photo-upload-submit'); 133 var $postBox = $('#id_body');
134 var $photoUploadSubmit = $('#photo-upload-submit');
134 135
135 $photoForm.ajaxForm({ 136 $photoForm.ajaxForm({
136 beforeSubmit: function(arr, $form, options) { 137 beforeSubmit: function(arr, $form, options) {
137 var fileObj = null; 138 var fileObj = null;
138 $.each(arr, function(index, val) { 139 $.each(arr, function(index, val) {
139 if (val.name == 'image_file') { 140 if (val.name == 'image_file') {
140 fileObj = val.value; 141 fileObj = val.value;
142 }
143 });
144 if (!fileObj) {
145 alert("Please choose a file to upload.");
146 return false;
141 } 147 }
142 }); 148 $photoUploadSubmit.attr('disabled', 'disabled').val('Uploading...');
143 if (!fileObj) { 149 return true;
144 alert("Please choose a file to upload."); 150 },
145 return false; 151 beforeSend: function() {
152 $photoProgress.progressbar({value: 0});
153 },
154 uploadProgress: function(event, position, total, percentComplete) {
155 if (percentComplete < 100) {
156 $photoProgress.progressbar({value: percentComplete});
157 }
158 else {
159 $photoProgress.progressbar({value: false});
160 }
161 },
162 success: function(resp, statusText, xhr, $form) {
163 $photoProgress.progressbar({value: 100});
164 if (resp.success) {
165 $postBox.val($postBox.val() + '\n![image](' + resp.url + ')');
166 alert("Success! The image code was added to your post.");
167 }
168 else {
169 alert('Error: ' + resp.msg);
170 }
171 },
172 complete: function(xhr) {
173 $photoProgress.progressbar({value: 0});
174 $photoForm.clearForm();
175 $photoUploadSubmit.removeAttr('disabled').val('Upload photo');
176 },
177 error: function(xhr, textStatus, ex) {
178 alert('Oops, there was an error: ' + ex);
146 } 179 }
147 $photoUploadSubmit.attr('disabled', 'disabled').val('Uploading...'); 180 });
148 return true; 181 }
149 },
150 beforeSend: function() {
151 $photoProgress.progressbar({value: 0});
152 },
153 uploadProgress: function(event, position, total, percentComplete) {
154 if (percentComplete < 100) {
155 $photoProgress.progressbar({value: percentComplete});
156 }
157 else {
158 $photoProgress.progressbar({value: false});
159 }
160 },
161 success: function(resp, statusText, xhr, $form) {
162 $photoProgress.progressbar({value: 100});
163 if (resp.success) {
164 $postBox.val($postBox.val() + '\n![image](' + resp.url + ')');
165 alert("Success! The image code was added to your post.");
166 }
167 else {
168 alert('Error: ' + resp.msg);
169 }
170 },
171 complete: function(xhr) {
172 $photoProgress.progressbar({value: 0});
173 $photoForm.clearForm();
174 $photoUploadSubmit.removeAttr('disabled').val('Upload photo');
175 },
176 error: function(xhr, textStatus, ex) {
177 alert('Oops, there was an error: ' + ex);
178 }
179 });
180 }); 182 });