var DzFactory = function () {
- this.createDropzone = function(element, target, maxImagesize) {
- return new Dropzone( element, {
+ this.createDropzone = function(dropSelector, textareaSelector, maxImagesize) {
+ return new Dropzone( dropSelector, {
paramName: 'userfile', // The name that will be used to transfer the file
maxFilesize: maxImagesize, // MB
url: '/media/photo/upload?response=url&album=',
},
init: function() {
this.on('success', function(file, serverResponse) {
- var _target = $(target)
- var resp = $(serverResponse).find('div#content').text()
- if (_target.setRangeText) {
+ const targetTextarea = document.getElementById(textareaSelector);
+ const bbcodeString = $(serverResponse).find('div#content').text();
+ if (targetTextarea.setRangeText) {
//if setRangeText function is supported by current browser
- _target.setRangeText(' ' + $.trim(resp) + ' ')
+ targetTextarea.setRangeText(' ' + $.trim(bbcodeString) + ' ');
} else {
- _target.focus()
- document.execCommand('insertText', false /*no UI*/, ' ' + $.trim(resp) + ' ');
+ targetTextarea.focus();
+ document.execCommand('insertText', false /*no UI*/, '\n' + $.trim(bbcodeString) + '\n');
}
});
this.on('complete', function(file) {
items.forEach((item) => {
if (item.kind === 'file') {
// adds the file to your dropzone instance
- dz.addFile(item.getAsFile())
+ dz.addFile(item.getAsFile());
}
})
},
items.forEach((item) => {
if (item.kind === 'file') {
// adds the file to your dropzone instance
- dz.addFile(item.getAsFile())
+ dz.addFile(item.getAsFile());
}
})
};
- this.setupDropzone = function(element, target, maxImagesize) {
- var dropzone = this.createDropzone(element, target, maxImagesize)
- $(element).on('paste', function(event) {
-
+ this.setupDropzone = function(dropSelector, textareaSelector, maxImagesize) {
+ var dropzone = this.createDropzone(dropSelector, textareaSelector, maxImagesize);
+ $(dropSelector).on('paste', function(event) {
dzFactory.copyPaste(event, dropzone);
})
};
</div>
</div>
<script>
- dzFactory.setupDropzone('#dropzone-{{$id}}', $('#comment-edit-text-{{$id}}'), {{$max_imagesize}});
+ dzFactory.setupDropzone('#dropzone-{{$id}}', 'comment-edit-text-{{$id}}', {{$max_imagesize}});
</script>
// To make dropzone fileupload work on editing a comment, we need to
// attach a new dropzone to modal
- dropzoneJotEdit = new Dropzone( '#jot-text-wrap', {
- paramName: 'userfile', // The name that will be used to transfer the file
- maxFilesize: '{{$max_imagesize}}', // MB
- url: '/media/photo/upload?response=url&album=',
- accept: function(file, done) {
- done();
- },
- init: function() {
- this.on('success', function(file, serverResponse) {
- var target = $('#profile-jot-text')
- var resp = $(serverResponse).find('div#content').text()
- if (target.setRangeText) {
- //if setRangeText function is supported by current browser
- target.setRangeText(' ' + $.trim(resp) + ' ')
- } else {
- target.focus()
- document.execCommand('insertText', false /*no UI*/, ' ' + $.trim(resp) + ' ');
- }
- });
- this.on('complete', function(file) {
- // Remove just uploaded file from dropzone, makes interface more clear.
- // Image can be seen in posting-preview
- // We need preview to get optical feedback about upload-progress.
- // you see success, when the bb-code link for image is inserted
- setTimeout(function(){
- dropzoneJotEdit.removeFile(file);
- },5000);
- });
- },
- });
-
- // Enables Copy&Paste for this dropzone
- $('#jot-text-wrap').on('paste', function(event){
- const items = (event.clipboardData || event.originalEvent.clipboardData).items;
- items.forEach((item) => {
- if (item.kind === 'file') {
- // adds the file to your dropzone instance
- dropzoneJotEdit.addFile(item.getAsFile())
- }
- })
- })
-
+ console.log("modal.js max_imagesize",'{{$max_imagesize}}');
+ dzFactory.setupDropzone('#jot-text-wrap', 'profile-jot-text', '{{$max_imagesize}}');
modal.show();
$("#jot-popup").show();
<script>
$('[id=comment-fake-text-{{$id}}]').on('focus', function() {
- dzFactory.setupDropzone('#dropzone-{{$id}}', $('#comment-edit-text-{{$id}}'), {{$max_imagesize}});
- $('[id=comment-fake-text-{{$id}}]') .prop('focus', null).off('focus')
- $('[id=comment-{{$id}}]') .prop('click', null).off('click')
+ dzFactory.setupDropzone('#dropzone-{{$id}}', 'comment-edit-text-{{$id}}', {{$max_imagesize}});
+ $('[id=comment-fake-text-{{$id}}]').prop('focus', null).off('focus')
+ $('[id=comment-{{$id}}]').prop('click', null).off('click')
});
$('[id=comment-{{$id}}]').on('click', function() {
- dzFactory.setupDropzone('#dropzone-{{$id}}', $('#comment-edit-text-{{$id}}'), {{$max_imagesize}});
- $('[id=comment-fake-text-{{$id}}]') .prop('focus', null).off('focus')
- $('[id=comment-{{$id}}]') .prop('click', null).off('click')
+ dzFactory.setupDropzone('#dropzone-{{$id}}', 'comment-edit-text-{{$id}}', {{$max_imagesize}});
+ $('[id=comment-fake-text-{{$id}}]').prop('focus', null).off('focus')
+ $('[id=comment-{{$id}}]').prop('click', null).off('click')
});
</script>
</script>
<script>
- dzFactory.setupDropzone('#jot-text-wrap', $('#profile-jot-text'), {{$max_imagesize}});
+ dzFactory.setupDropzone('#jot-text-wrap', 'profile-jot-text', {{$max_imagesize}});
</script>