changes in case of codereview
This commit is contained in:
parent
0cc2e1c22a
commit
16f065e260
5 changed files with 23 additions and 64 deletions
|
@ -1,6 +1,6 @@
|
|||
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=',
|
||||
|
@ -9,14 +9,14 @@ var DzFactory = function () {
|
|||
},
|
||||
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) {
|
||||
|
@ -35,7 +35,7 @@ var DzFactory = function () {
|
|||
items.forEach((item) => {
|
||||
if (item.kind === 'file') {
|
||||
// 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) => {
|
||||
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);
|
||||
})
|
||||
};
|
||||
|
|
|
@ -96,5 +96,5 @@
|
|||
</div>
|
||||
</div>
|
||||
<script>
|
||||
dzFactory.setupDropzone('#dropzone-{{$id}}', $('#comment-edit-text-{{$id}}'), {{$max_imagesize}});
|
||||
dzFactory.setupDropzone('#dropzone-{{$id}}', 'comment-edit-text-{{$id}}', {{$max_imagesize}});
|
||||
</script>
|
||||
|
|
|
@ -293,48 +293,8 @@ function editpost(url) {
|
|||
|
||||
// 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();
|
||||
|
|
|
@ -67,12 +67,12 @@
|
|||
|
||||
<script>
|
||||
$('[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-{{$id}}]').prop('click', null).off('click')
|
||||
});
|
||||
$('[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-{{$id}}]').prop('click', null).off('click')
|
||||
});
|
||||
|
|
|
@ -180,5 +180,5 @@ can load different content into the jot modal (e.g. the item edit jot)
|
|||
</script>
|
||||
|
||||
<script>
|
||||
dzFactory.setupDropzone('#jot-text-wrap', $('#profile-jot-text'), {{$max_imagesize}});
|
||||
dzFactory.setupDropzone('#jot-text-wrap', 'profile-jot-text', {{$max_imagesize}});
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue