Project

General

Profile

Feature #26071 » 0001-Generate-markup-for-uploaded-image-dropped-into-wiki.patch

Felix Gliesche, 2017-05-30 17:40

View differences:

lib/redmine/mime_type.rb
map
end
# returns all full mime types for a given (top level) type
def self.by_type(type)
MIME_TYPES.keys.select{|m| m.start_with? "#{type}/"}
end
# returns mime type for name or nil if unknown
def self.of(name)
return nil unless name.present?
lib/redmine/wiki_formatting/markdown/helper.rb
javascript_include_tag('jstoolbar/jstoolbar') +
javascript_include_tag('jstoolbar/markdown') +
javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
javascript_tag("var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};") +
stylesheet_link_tag('jstoolbar')
end
@heads_for_wiki_formatter_included = true
lib/redmine/wiki_formatting/textile/helper.rb
content_for :header_tags do
javascript_include_tag('jstoolbar/jstoolbar-textile.min') +
javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
javascript_tag("var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};") +
stylesheet_link_tag('jstoolbar')
end
@heads_for_wiki_formatter_included = true
public/javascripts/attachments.js
progressEventHandler: onProgress.bind(progressSpan)
})
.done(function(result) {
addInlineAttachmentMarkup(file);
progressSpan.progressbar( 'value', 100 ).remove();
fileSpan.find('input.description, a').css('display', 'inline-block');
})
......
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');
......
}
}
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(){
(2-2/2)