1 var DzFactory = function () {
2 this.createDropzone = function(element, target, maxImagesize) {
3 return new Dropzone( element, {
4 paramName: 'userfile', // The name that will be used to transfer the file
5 maxFilesize: maxImagesize, // MB
6 url: '/media/photo/upload?response=url&album=',
7 accept: function(file, done) {
11 this.on('success', function(file, serverResponse) {
12 var _target = $(target)
13 var resp = $(serverResponse).find('div#content').text()
14 if (_target.setRangeText) {
15 //if setRangeText function is supported by current browser
16 _target.setRangeText(' ' + $.trim(resp) + ' ')
19 document.execCommand('insertText', false /*no UI*/, ' ' + $.trim(resp) + ' ');
22 this.on('complete', function(file) {
24 // Remove just uploaded file from dropzone, makes interface more clear.
25 // Image can be seen in posting-preview
26 // We need preview to get optical feedback about upload-progress.
27 // you see success, when the bb-code link for image is inserted
28 setTimeout(function(){
33 paste: function(event){
34 const items = (event.clipboardData || event.originalEvent.clipboardData).items;
35 items.forEach((item) => {
36 if (item.kind === 'file') {
37 // adds the file to your dropzone instance
38 dz.addFile(item.getAsFile())
45 this.copyPaste = function(event, dz) {
46 const items = (event.clipboardData || event.originalEvent.clipboardData).items;
47 items.forEach((item) => {
48 if (item.kind === 'file') {
49 // adds the file to your dropzone instance
50 dz.addFile(item.getAsFile())
55 this.setupDropzone = function(element, target, maxImagesize) {
56 var dropzone = this.createDropzone(element, target, maxImagesize)
57 $(element).on('paste', function(event) {
59 dzFactory.copyPaste(event, dropzone);