summaryrefslogtreecommitdiffstats
path: root/public/javascripts
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2017-06-07 21:01:45 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2017-06-07 21:01:45 +0000
commit7f4767418befd064cfeb65b034eeeb2832a3c264 (patch)
treeea968975bab97c9a60ac376b620866a6a5ed0a10 /public/javascripts
parent43c69c370c62da8fc976a53da4eb947c38728212 (diff)
downloadredmine-7f4767418befd064cfeb65b034eeeb2832a3c264.tar.gz
redmine-7f4767418befd064cfeb65b034eeeb2832a3c264.zip
Generate markup for uploaded image dropped into wiki-edit textarea (#26071).
Patch by Felix Gliesche. git-svn-id: http://svn.redmine.org/redmine/trunk@16643 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'public/javascripts')
-rw-r--r--public/javascripts/attachments.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/public/javascripts/attachments.js b/public/javascripts/attachments.js
index 8700aafee..9afa73b17 100644
--- a/public/javascripts/attachments.js
+++ b/public/javascripts/attachments.js
@@ -58,6 +58,7 @@ function ajaxUpload(file, attachmentId, fileSpan, inputEl) {
progressEventHandler: onProgress.bind(progressSpan)
})
.done(function(result) {
+ addInlineAttachmentMarkup(file);
progressSpan.progressbar( 'value', 100 ).remove();
fileSpan.find('input.description, a').css('display', 'inline-block');
})
@@ -175,9 +176,11 @@ function handleFileDropEvent(e) {
blockEventPropagation(e);
if ($.inArray('Files', e.dataTransfer.types) > -1) {
+ handleFileDropEvent.target = e.target;
uploadAndAttachFiles(e.dataTransfer.files, $('input:file.filedrop').first());
}
}
+handleFileDropEvent.target = '';
function dragOverHandler(e) {
$(this).addClass('fileover');
@@ -204,6 +207,49 @@ function setupFileDrop() {
}
}
+function addInlineAttachmentMarkup(file) {
+ // insert uploaded image inline if dropped area is currently focused textarea
+ if($(handleFileDropEvent.target).hasClass('wiki-edit') && $.inArray(file.type, window.wikiImageMimeTypes) > -1) {
+ var $textarea = $(handleFileDropEvent.target);
+ var cursorPosition = $textarea.prop('selectionStart');
+ var description = $textarea.val();
+ var sanitizedFilename = file.name.replace(/[\/\?\%\*\:\|\"\'<>\n\r]+/, '_');
+ var inlineFilename = encodeURIComponent(sanitizedFilename);
+ var newLineBefore = true;
+ var newLineAfter = true;
+ if(cursorPosition === 0 || description.substr(cursorPosition-1,1).match(/\r|\n/)) {
+ newLineBefore = false;
+ }
+ if(description.substr(cursorPosition,1).match(/\r|\n/)) {
+ newLineAfter = false;
+ }
+
+ $textarea.val(
+ description.substring(0, cursorPosition)
+ + (newLineBefore ? '\n' : '')
+ + inlineFilename
+ + (newLineAfter ? '\n' : '')
+ + description.substring(cursorPosition, description.length)
+ );
+
+ $textarea.prop({
+ 'selectionStart': cursorPosition + newLineBefore,
+ 'selectionEnd': cursorPosition + inlineFilename.length + newLineBefore
+ });
+ $textarea.closest('.jstEditor')
+ .siblings('.jstElements')
+ .find('.jstb_img').click();
+
+ // move cursor into next line
+ cursorPosition = $textarea.prop('selectionStart');
+ $textarea.prop({
+ 'selectionStart': cursorPosition + 1,
+ 'selectionEnd': cursorPosition + 1
+ });
+
+ }
+}
+
$(document).ready(setupFileDrop);
$(document).ready(function(){
$("input.deleted_attachment").change(function(){