Skip to content

Commit f571033

Browse files
authored
Merge pull request refactory-id#247 from jacargentina/add-drop-as-embed-support
Allow drag and drop Images and embed as data-uri
2 parents 40058aa + 199b57d commit f571033

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

js/bootstrap-markdown.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,25 @@
493493
}
494494
}
495495

496+
// enable data-uris via drag and drop
497+
if (options.enableDropDataUri === true) {
498+
this.$editor.on('drop', function(e) {
499+
var caretPos = textarea.prop('selectionStart');
500+
e.stopPropagation();
501+
e.preventDefault();
502+
$.each(e.originalEvent.dataTransfer.files, function(index, file){
503+
var fileReader = new FileReader();
504+
fileReader.onload = (function(file) {
505+
return function(e) {
506+
var text = textarea.val();
507+
textarea.val(text.substring(0, caretPos) + '\n<img src="'+ e.target.result +'" />\n' + text.substring(caretPos) );
508+
};
509+
})(file);
510+
fileReader.readAsDataURL(file);
511+
});
512+
});
513+
}
514+
496515
// Trigger the onShow hook
497516
options.onShow(this);
498517

@@ -950,6 +969,7 @@
950969
initialstate: 'editor',
951970
parser: null,
952971
dropZoneOptions: null,
972+
enableDropDataUri: false,
953973

954974
/* Buttons Properties */
955975
buttons: [

0 commit comments

Comments
 (0)