Skip to content

Commit c6117fc

Browse files
authored
Merge pull request refactory-id#305 from jacargentina/master
Implements refactory-id#304: Feature request: support binary files embed as data URIs
2 parents c7ceaae + 4181586 commit c6117fc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

js/bootstrap-markdown.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,13 @@
509509
$.each(e.originalEvent.dataTransfer.files, function(index, file){
510510
var fileReader = new FileReader();
511511
fileReader.onload = (function(file) {
512+
var type = file.type.split('/')[0];
512513
return function(e) {
513514
var text = textarea.val();
514-
textarea.val(text.substring(0, caretPos) + '\n<img src="'+ e.target.result +'" />\n' + text.substring(caretPos) );
515+
if (type === 'image')
516+
textarea.val(text.substring(0, caretPos) + '\n<img src="'+ e.target.result +'" />\n' + text.substring(caretPos) );
517+
else
518+
textarea.val(text.substring(0, caretPos) + '\n<a href="'+ e.target.result +'">Download ' + file.name + '</a>\n' + text.substring(caretPos) );
515519
};
516520
})(file);
517521
fileReader.readAsDataURL(file);

0 commit comments

Comments
 (0)