comparison static/js/markitup/sets/markdown/set.js @ 722:71d17d267e27

Added an ajax form to upload photos & update post box w/image code.
author Brian Neal <bgneal@gmail.com>
date Sat, 21 Sep 2013 17:00:49 -0500
parents ad69236e8501
children 682b159f3763
comparison
equal deleted inserted replaced
721:378b55b81de3 722:71d17d267e27
124 } 124 }
125 }); 125 });
126 } 126 }
127 return false; 127 return false;
128 }); 128 });
129
130 var $photoProgress = $('#photo-upload-progress');
131 var $photoForm = $('#photo-upload-form');
132 var $postBox = $('#id_body');
133 var $photoUploadSubmit = $('#photo-upload-submit');
134
135 $photoForm.ajaxForm({
136 beforeSubmit: function(arr, $form, options) {
137 var fileObj = null;
138 $.each(arr, function(index, val) {
139 if (val.name == 'image_file') {
140 fileObj = val.value;
141 }
142 });
143 if (!fileObj) {
144 alert("Please choose a file to upload.");
145 return false;
146 }
147 $photoUploadSubmit.attr('disabled', 'disabled').val('Uploading...');
148 return true;
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 });
129 }); 180 });