]> BookStack Code Mirror - bookstack/blobdiff - resources/js/wysiwyg/drop-paste-handling.js
Refactored common list handling operations to new class
[bookstack] / resources / js / wysiwyg / drop-paste-handling.js
index 1da13c88835dcd0a4d1f24e644289ddb9c019792..866d25a24e828a5fbcbf99ab1bb51a950563bc69 100644 (file)
@@ -43,7 +43,6 @@ function paste(editor, options, event) {
                 editor.dom.replace(newEl, id);
             }).catch(err => {
                 editor.dom.remove(id);
-                // TODO - Check we have this translation
                 window.$events.emit('error', options.translations.imageUploadErrorText);
                 console.log(err);
             });
@@ -61,13 +60,7 @@ async function uploadImageFile(file, pageId) {
         throw new Error(`Not an image file`);
     }
 
-    let ext = 'png';
-    if (file.name) {
-        let fileNameMatches = file.name.match(/\.(.+)$/);
-        if (fileNameMatches.length > 1) ext = fileNameMatches[1];
-    }
-
-    const remoteFilename = "image-" + Date.now() + "." + ext;
+    const remoteFilename = file.name || `image-${Date.now()}.png`;
     const formData = new FormData();
     formData.append('file', file, remoteFilename);
     formData.append('uploaded_to', pageId);
@@ -139,9 +132,9 @@ function drop(editor, options, event) {
             const range = editor.selection.getRng();
             const selectedNodeRoot = selectedNode.closest('body > *');
             if (range.startOffset > (range.startContainer.length / 2)) {
-                editor.$(selectedNodeRoot).after(draggedContentEditable);
+                selectedNodeRoot.after(draggedContentEditable);
             } else {
-                editor.$(selectedNodeRoot).before(draggedContentEditable);
+                selectedNodeRoot.before(draggedContentEditable);
             }
         });
     }