changes in case of codereview

This commit is contained in:
Jakobus Schürz 2023-03-15 21:05:16 +01:00
parent 0cc2e1c22a
commit 16f065e260
5 changed files with 23 additions and 64 deletions

View file

@ -1,6 +1,6 @@
var DzFactory = function () { var DzFactory = function () {
this.createDropzone = function(element, target, maxImagesize) { this.createDropzone = function(dropSelector, textareaSelector, maxImagesize) {
return new Dropzone( element, { return new Dropzone( dropSelector, {
paramName: 'userfile', // The name that will be used to transfer the file paramName: 'userfile', // The name that will be used to transfer the file
maxFilesize: maxImagesize, // MB maxFilesize: maxImagesize, // MB
url: '/media/photo/upload?response=url&album=', url: '/media/photo/upload?response=url&album=',
@ -9,14 +9,14 @@ var DzFactory = function () {
}, },
init: function() { init: function() {
this.on('success', function(file, serverResponse) { this.on('success', function(file, serverResponse) {
var _target = $(target) const targetTextarea = document.getElementById(textareaSelector);
var resp = $(serverResponse).find('div#content').text() const bbcodeString = $(serverResponse).find('div#content').text();
if (_target.setRangeText) { if (targetTextarea.setRangeText) {
//if setRangeText function is supported by current browser //if setRangeText function is supported by current browser
_target.setRangeText(' ' + $.trim(resp) + ' ') targetTextarea.setRangeText(' ' + $.trim(bbcodeString) + ' ');
} else { } else {
_target.focus() targetTextarea.focus();
document.execCommand('insertText', false /*no UI*/, ' ' + $.trim(resp) + ' '); document.execCommand('insertText', false /*no UI*/, '\n' + $.trim(bbcodeString) + '\n');
} }
}); });
this.on('complete', function(file) { this.on('complete', function(file) {
@ -35,7 +35,7 @@ var DzFactory = function () {
items.forEach((item) => { items.forEach((item) => {
if (item.kind === 'file') { if (item.kind === 'file') {
// adds the file to your dropzone instance // adds the file to your dropzone instance
dz.addFile(item.getAsFile()) dz.addFile(item.getAsFile());
} }
}) })
}, },
@ -47,15 +47,14 @@ var DzFactory = function () {
items.forEach((item) => { items.forEach((item) => {
if (item.kind === 'file') { if (item.kind === 'file') {
// adds the file to your dropzone instance // adds the file to your dropzone instance
dz.addFile(item.getAsFile()) dz.addFile(item.getAsFile());
} }
}) })
}; };
this.setupDropzone = function(element, target, maxImagesize) { this.setupDropzone = function(dropSelector, textareaSelector, maxImagesize) {
var dropzone = this.createDropzone(element, target, maxImagesize) var dropzone = this.createDropzone(dropSelector, textareaSelector, maxImagesize);
$(element).on('paste', function(event) { $(dropSelector).on('paste', function(event) {
dzFactory.copyPaste(event, dropzone); dzFactory.copyPaste(event, dropzone);
}) })
}; };

View file

@ -96,5 +96,5 @@
</div> </div>
</div> </div>
<script> <script>
dzFactory.setupDropzone('#dropzone-{{$id}}', $('#comment-edit-text-{{$id}}'), {{$max_imagesize}}); dzFactory.setupDropzone('#dropzone-{{$id}}', 'comment-edit-text-{{$id}}', {{$max_imagesize}});
</script> </script>

View file

@ -293,48 +293,8 @@ function editpost(url) {
// To make dropzone fileupload work on editing a comment, we need to // To make dropzone fileupload work on editing a comment, we need to
// attach a new dropzone to modal // attach a new dropzone to modal
dropzoneJotEdit = new Dropzone( '#jot-text-wrap', { console.log("modal.js max_imagesize",'{{$max_imagesize}}');
paramName: 'userfile', // The name that will be used to transfer the file dzFactory.setupDropzone('#jot-text-wrap', 'profile-jot-text', '{{$max_imagesize}}');
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())
}
})
})
modal.show(); modal.show();
$("#jot-popup").show(); $("#jot-popup").show();

View file

@ -67,13 +67,13 @@
<script> <script>
$('[id=comment-fake-text-{{$id}}]').on('focus', function() { $('[id=comment-fake-text-{{$id}}]').on('focus', function() {
dzFactory.setupDropzone('#dropzone-{{$id}}', $('#comment-edit-text-{{$id}}'), {{$max_imagesize}}); dzFactory.setupDropzone('#dropzone-{{$id}}', 'comment-edit-text-{{$id}}', {{$max_imagesize}});
$('[id=comment-fake-text-{{$id}}]') .prop('focus', null).off('focus') $('[id=comment-fake-text-{{$id}}]').prop('focus', null).off('focus')
$('[id=comment-{{$id}}]') .prop('click', null).off('click') $('[id=comment-{{$id}}]').prop('click', null).off('click')
}); });
$('[id=comment-{{$id}}]').on('click', function() { $('[id=comment-{{$id}}]').on('click', function() {
dzFactory.setupDropzone('#dropzone-{{$id}}', $('#comment-edit-text-{{$id}}'), {{$max_imagesize}}); dzFactory.setupDropzone('#dropzone-{{$id}}', 'comment-edit-text-{{$id}}', {{$max_imagesize}});
$('[id=comment-fake-text-{{$id}}]') .prop('focus', null).off('focus') $('[id=comment-fake-text-{{$id}}]').prop('focus', null).off('focus')
$('[id=comment-{{$id}}]') .prop('click', null).off('click') $('[id=comment-{{$id}}]').prop('click', null).off('click')
}); });
</script> </script>

View file

@ -180,5 +180,5 @@ can load different content into the jot modal (e.g. the item edit jot)
</script> </script>
<script> <script>
dzFactory.setupDropzone('#jot-text-wrap', $('#profile-jot-text'), {{$max_imagesize}}); dzFactory.setupDropzone('#jot-text-wrap', 'profile-jot-text', {{$max_imagesize}});
</script> </script>