58 |
58 |
progressEventHandler: onProgress.bind(progressSpan)
|
59 |
59 |
})
|
60 |
60 |
.done(function(result) {
|
|
61 |
addInlineAttachmentMarkup(file);
|
61 |
62 |
progressSpan.progressbar( 'value', 100 ).remove();
|
62 |
63 |
fileSpan.find('input.description, a').css('display', 'inline-block');
|
63 |
64 |
})
|
... | ... | |
175 |
176 |
blockEventPropagation(e);
|
176 |
177 |
|
177 |
178 |
if ($.inArray('Files', e.dataTransfer.types) > -1) {
|
|
179 |
handleFileDropEvent.target = e.target;
|
178 |
180 |
uploadAndAttachFiles(e.dataTransfer.files, $('input:file.filedrop').first());
|
179 |
181 |
}
|
180 |
182 |
}
|
|
183 |
handleFileDropEvent.target = '';
|
181 |
184 |
|
182 |
185 |
function dragOverHandler(e) {
|
183 |
186 |
$(this).addClass('fileover');
|
... | ... | |
204 |
207 |
}
|
205 |
208 |
}
|
206 |
209 |
|
|
210 |
function addInlineAttachmentMarkup(file) {
|
|
211 |
// insert uploaded image inline if dropped area is currently focused textarea
|
|
212 |
if($(handleFileDropEvent.target).hasClass('wiki-edit') && $.inArray(file.type, window.wikiImageMimeTypes) > -1) {
|
|
213 |
var $textarea = $(handleFileDropEvent.target);
|
|
214 |
var cursorPosition = $textarea.prop('selectionStart');
|
|
215 |
var description = $textarea.val();
|
|
216 |
var sanitizedFilename = file.name.replace(/[\/\?\%\*\:\|\"\'<>\n\r]+/, '_');
|
|
217 |
var inlineFilename = encodeURIComponent(sanitizedFilename);
|
|
218 |
var newLineBefore = true;
|
|
219 |
var newLineAfter = true;
|
|
220 |
if(cursorPosition === 0 || description.substr(cursorPosition-1,1).match(/\r|\n/)) {
|
|
221 |
newLineBefore = false;
|
|
222 |
}
|
|
223 |
if(description.substr(cursorPosition,1).match(/\r|\n/)) {
|
|
224 |
newLineAfter = false;
|
|
225 |
}
|
|
226 |
|
|
227 |
$textarea.val(
|
|
228 |
description.substring(0, cursorPosition)
|
|
229 |
+ (newLineBefore ? '\n' : '')
|
|
230 |
+ inlineFilename
|
|
231 |
+ (newLineAfter ? '\n' : '')
|
|
232 |
+ description.substring(cursorPosition, description.length)
|
|
233 |
);
|
|
234 |
|
|
235 |
$textarea.prop({
|
|
236 |
'selectionStart': cursorPosition + newLineBefore,
|
|
237 |
'selectionEnd': cursorPosition + inlineFilename.length + newLineBefore
|
|
238 |
});
|
|
239 |
$textarea.closest('.jstEditor')
|
|
240 |
.siblings('.jstElements')
|
|
241 |
.find('.jstb_img').click();
|
|
242 |
|
|
243 |
// move cursor into next line
|
|
244 |
cursorPosition = $textarea.prop('selectionStart');
|
|
245 |
$textarea.prop({
|
|
246 |
'selectionStart': cursorPosition + 1,
|
|
247 |
'selectionEnd': cursorPosition + 1
|
|
248 |
});
|
|
249 |
|
|
250 |
}
|
|
251 |
}
|
|
252 |
|
207 |
253 |
$(document).ready(setupFileDrop);
|
208 |
254 |
$(document).ready(function(){
|
209 |
255 |
$("input.deleted_attachment").change(function(){
|