Skip to content

Commit

Permalink
Merge branch 'cw/texteditor-reusability'
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkwinkelmann committed Oct 14, 2023
2 parents f66c696 + 12bcbc7 commit e379d76
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions js/src/forum/addUploadButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,26 @@ export default function () {
}
});

this.dragAndDrop = new DragAndDrop((files) => this.uploader.upload(files), this.$().parents('.Composer')[0]);
// Gracefully fail if the TextEditor was used in a non-Composer context
// Using a custom method to retrieve the target allows other extensions to still use this feature by returning an alternate container
const dragAndDropTarget = this.fofUploadDragAndDropTarget();

if (dragAndDropTarget) {
this.dragAndDrop = new DragAndDrop((files) => this.uploader.upload(files), dragAndDropTarget);
}

new PasteClipboard((files) => this.uploader.upload(files), this.$('.TextEditor-editor')[0]);
});

extend(TextEditor.prototype, 'onremove', function (f_, vnode) {
if (!app.forum.attribute('fof-upload.canUpload')) return;

this.dragAndDrop.unload();
if (this.dragAndDrop) {
this.dragAndDrop.unload();
}
});

TextEditor.prototype.fofUploadDragAndDropTarget = function () {
return this.$().parents('.Composer')[0];
};
}

0 comments on commit e379d76

Please sign in to comment.