Skip to content

Commit

Permalink
remove unnecessary changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-kotov-dx committed Apr 14, 2022
1 parent b07a965 commit 597fb6c
Showing 1 changed file with 26 additions and 33 deletions.
59 changes: 26 additions & 33 deletions modules/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,35 @@ class Uploader extends Module {
}

addDropHandler() {
this.bindedDropHandler = this.dropHandler.bind(this);
this.quill.root.addEventListener('drop', this.bindedDropHandler);
}

dropHandler(e) {
const noFiles = e.dataTransfer.files.length === 0;
const { onDrop } = this.options;

if (onDrop && typeof onDrop === 'function') {
onDrop(e);
}

if (noFiles || this.preventImageUpload) {
return;
}
this.quill.root.addEventListener('drop', e => {
const noFiles = e.dataTransfer.files.length === 0;
const { onDrop } = this.options;

e.preventDefault();
let native;
if (onDrop && typeof onDrop === 'function') {
onDrop(e);
}

if (document.caretRangeFromPoint) {
native = document.caretRangeFromPoint(e.clientX, e.clientY);
} else if (document.caretPositionFromPoint) {
const position = document.caretPositionFromPoint(e.clientX, e.clientY);
native = document.createRange();
native.setStart(position.offsetNode, position.offset);
native.setEnd(position.offsetNode, position.offset);
} else {
return;
}
const normalized = this.quill.selection.normalizeNative(native);
const range = this.quill.selection.normalizedToRange(normalized);
this.upload(range, e.dataTransfer.files);
}
if (noFiles || this.preventImageUpload) {
return;
}

removeDropHandler() {
this.quill.root.removeEventListener('drop', this.bindedDropHandler);
e.preventDefault();
let native;

if (document.caretRangeFromPoint) {
native = document.caretRangeFromPoint(e.clientX, e.clientY);
} else if (document.caretPositionFromPoint) {
const position = document.caretPositionFromPoint(e.clientX, e.clientY);
native = document.createRange();
native.setStart(position.offsetNode, position.offset);
native.setEnd(position.offsetNode, position.offset);
} else {
return;
}
const normalized = this.quill.selection.normalizeNative(native);
const range = this.quill.selection.normalizedToRange(normalized);
this.upload(range, e.dataTransfer.files);
});
}

preventImageUploading(value) {
Expand Down

0 comments on commit 597fb6c

Please sign in to comment.