striven-editor

Maintained and contributed to an open source WYSIWYG editor as an internship project that made it to production and was adopted by the company I was working at.
git clone https://unitehenry.com/git/striven-editor.git
Log | Files | Refs | README | LICENSE

commit 2f6f2c44c0b22d113c06da7b0931f0f83030bee3
parent 2ad53cf6b5af40f564e919e708da8552b3daa360
Author: unitehenry <unitehenry@gmail.com>
Date:   Thu, 31 Oct 2019 08:18:42 -0400

datatransfer file check

Diffstat:
Msrc/striveneditor.css | 1+
Msrc/striveneditor.js | 15++++++++-------
2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/striveneditor.css b/src/striveneditor.css @@ -43,6 +43,7 @@ margin: auto; position: absolute; border: 5px dashed #ddd; + background-color: rgba(0, 0, 0, .025); display: flex; justify-content: center; align-items: center; diff --git a/src/striveneditor.js b/src/striveneditor.js @@ -180,7 +180,7 @@ export default class StrivenEditor { window.getSelection().removeAllRanges(); window.getSelection().addRange(this.range); - + const command = optionEl.id.split("-")[1]; switch (command) { @@ -766,8 +766,7 @@ export default class StrivenEditor { }, false); this.body.ondragenter = e => { - console.log(e) - if (!this.body.querySelector('.se-file-drop-dropzone')) { + if (!this.body.querySelector('.se-file-drop-dropzone') && e.dataTransfer.types.includes('Files')) { const dropzone = document.createElement("div"); const dropzoneTextEl = document.createElement("p"); @@ -789,14 +788,16 @@ export default class StrivenEditor { } this.body.ondrop = e => { - const dropzone = this.body.querySelector('.se-file-drop-dropzone'); + const dropzone = this.body.querySelector('.se-file-drop-dropzone'); dropzone && dropzone.remove(); e.preventDefault(); - const file = (e.dataTransfer.files.length && e.dataTransfer.files[0]); + if (e.dataTransfer.types.includes('Files')) { + const file = (e.dataTransfer.files.length && e.dataTransfer.files[0]); - this.attachFile(file); + this.attachFile(file); + } } this.isEdge && (this.body.ondragover = e => e.preventDefault()); @@ -1071,7 +1072,7 @@ export default class StrivenEditor { validateFile(file) { const extension = (file && file.type.split('/').pop()); - if(extension) { + if (extension) { return this.options.extensions.includes(`.${extension}`); } else { return false;