1 var DzFactory = function () {
2 this.createDropzone = function(dropSelector, textareaElementId) {
3 return new Dropzone(dropSelector, {
4 paramName: 'userfile', // The name that will be used to transfer the file
5 maxFilesize: max_imagesize, // MB
6 url: '/media/photo/upload?album=',
7 acceptedFiles: 'image/*',
9 accept: function(file, done) {
13 this.on('success', function(file, serverResponse) {
14 const targetTextarea = document.getElementById(textareaElementId);
15 if (targetTextarea.setRangeText) {
16 //if setRangeText function is supported by current browser
17 targetTextarea.setRangeText(' ' + $.trim(serverResponse) + ' ');
19 targetTextarea.focus();
20 document.execCommand('insertText', false /*no UI*/, '\n' + $.trim(serverResponse) + '\n');
23 this.on('complete', function(file) {
25 // Remove just uploaded file from dropzone, makes interface more clear.
26 // Image can be seen in posting-preview
27 // We need preview to get optical feedback about upload-progress.
28 // you see success, when the bb-code link for image is inserted
29 setTimeout(function(){
34 paste: function(event){
35 const items = (event.clipboardData || event.originalEvent.clipboardData).items;
36 items.forEach((item) => {
37 if (item.kind === 'file') {
38 // adds the file to your dropzone instance
39 dz.addFile(item.getAsFile());
46 this.copyPaste = function(event, dz) {
47 const items = (event.clipboardData || event.originalEvent.clipboardData).items;
48 items.forEach((item) => {
49 if (item.kind === 'file') {
50 // adds the file to your dropzone instance
51 dz.addFile(item.getAsFile());
56 this.setupDropzone = function(dropSelector, textareaElementId) {
57 var dropzone = this.createDropzone(dropSelector, textareaElementId);
58 $(dropSelector).on('paste', function(event) {
59 dzFactory.copyPaste(event, dropzone);