]> git.mxchange.org Git - friendica.git/commitdiff
changes in case of codereview
authorJakobus Schürz <jakobus.schuerz@schuerz.at>
Wed, 15 Mar 2023 20:05:16 +0000 (21:05 +0100)
committerJakobus Schürz <jakobus.schuerz@schuerz.at>
Sun, 19 Mar 2023 17:52:45 +0000 (18:52 +0100)
view/js/dropzone-factory.js
view/templates/item/compose.tpl
view/theme/frio/js/modal.js
view/theme/frio/templates/comment_item.tpl
view/theme/frio/templates/jot.tpl

index fe6c4448b2e3f6e3cc97343673f3e2036ca63273..5aaab503622be770c3ad8494972e479107d7a08e 100644 (file)
@@ -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);
                })
        };
index 07db40d9c6b28e9e4bda69747f2c3a78debb6229..499dfaffb2120a12d11de02bd66d08bb411d9139 100644 (file)
@@ -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>
index 705f472c431a3adf7cdccea5f1db4d7c96d0a2dc..85c258c92f5cca98ee4322ca05f23617a0591377 100644 (file)
@@ -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();
index b61c1d6f878431d19376065da246213d00572086..3d9860a10497d8ed099f700aaa0a074cd116b14b 100644 (file)
 
 <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>
index 1b77ded421cb1a4621e5ddb6520dba23408b60fb..325c8d5b3b5138a93c617cfb176e059158519811 100644 (file)
@@ -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>