fixes image uploads

if images had special regex characters in them upload text was failing
v1.18.x
barisusakli 11 years ago
parent 90e398e5c9
commit 970639274e

@ -110,7 +110,6 @@ define(['taskbar'], function(taskbar) {
} }
function removeDraft(save_id) { function removeDraft(save_id) {
console.log('removing draft');
return localStorage.removeItem(save_id); return localStorage.removeItem(save_id);
} }
@ -273,6 +272,10 @@ define(['taskbar'], function(taskbar) {
}); });
} }
function escapeRegExp(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
};
function uploadContentFiles(params) { function uploadContentFiles(params) {
var files = params.files, var files = params.files,
post_uuid = params.post_uuid, post_uuid = params.post_uuid,
@ -299,10 +302,15 @@ define(['taskbar'], function(taskbar) {
textarea.val(text); textarea.val(text);
uploadForm.off('submit').submit(function() { uploadForm.off('submit').submit(function() {
function updateTextArea(filename, text) {
var current = textarea.val();
var re = new RegExp(escapeRegExp(filename) + "]\\([^)]+\\)", 'g');
textarea.val(current.replace(re, filename + '](' + text + ')'));
}
$(this).find('#postUploadCsrf').val($('#csrf_token').val()); $(this).find('#postUploadCsrf').val($('#csrf_token').val());
if(formData) { if (formData) {
formData.append('_csrf', $('#csrf_token').val()); formData.append('_csrf', $('#csrf_token').val());
} }
@ -317,15 +325,14 @@ define(['taskbar'], function(taskbar) {
xhr = maybeParse(xhr); xhr = maybeParse(xhr);
app.alertError('Error uploading file!\nStatus : ' + xhr.status + '\nMessage : ' + xhr.responseText); app.alertError('Error uploading file!\nStatus : ' + xhr.status + '\nMessage : ' + xhr.responseText);
if (typeof callback == 'function') if (typeof callback === 'function') {
callback(xhr); callback(xhr);
}
}, },
uploadProgress: function(event, position, total, percent) { uploadProgress: function(event, position, total, percent) {
var current = textarea.val();
for(var i=0; i < files.length; ++i) { for(var i=0; i < files.length; ++i) {
var re = new RegExp(files[i].name + "]\\([^)]+\\)", 'g'); updateTextArea(files[i].name, 'uploading' + percent + '%');
textarea.val(current.replace(re, files[i].name+'](uploading ' + percent + '%)'));
} }
}, },
@ -334,15 +341,14 @@ define(['taskbar'], function(taskbar) {
if(uploads && uploads.length) { if(uploads && uploads.length) {
for(var i=0; i<uploads.length; ++i) { for(var i=0; i<uploads.length; ++i) {
var current = textarea.val(); updateTextArea(uploads[i].name, uploads[i].url);
var re = new RegExp(uploads[i].name + "]\\([^)]+\\)", 'g');
textarea.val(current.replace(re, uploads[i].name + '](' + uploads[i].url + ')'));
} }
} }
textarea.focus(); textarea.focus();
if (typeof callback == 'function') if (typeof callback === 'function') {
callback(null, uploads); callback(null, uploads);
}
}, },
complete: function() { complete: function() {

Loading…
Cancel
Save