Fix the handling of attachments when editing messages
authorAlexander Ebert <ebert@woltlab.com>
Wed, 28 Jun 2023 16:02:46 +0000 (18:02 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 28 Jun 2023 16:02:46 +0000 (18:02 +0200)
wcfsetup/install/files/js/WCF.Attachment.js

index 45895d0355f7f5cf2461df87c5a9773d1cdc066a..097d768721e084669bc247f9a1f2aa82a567a78b 100644 (file)
@@ -146,10 +146,20 @@ WCF.Attachment.Upload = WCF.Upload.extend({
                                        });
                                
                                const ckeditor = getCkeditor(this._sourceElement);
-                               if (ckeditor.getHtml() === "") {
-                                       // This check is performed during the CKEditor initialization,
-                                       // but the triggered event occurs too early for jQuery code.
-                                       discardAllAttachments();
+                               if (ckeditor) {
+                                       if (ckeditor.getHtml() === "") {
+                                               // This check is performed during the CKEditor initialization,
+                                               // but the triggered event occurs too early for jQuery code.
+                                               discardAllAttachments();
+                                       }
+                               } else {
+                                       listenToCkeditor(this._sourceElement).ready(({ ckeditor }) => {
+                                               if (ckeditor.getHtml() === "") {
+                                                       // This check is performed during the CKEditor initialization,
+                                                       // but the triggered event occurs too early for jQuery code.
+                                                       discardAllAttachments();
+                                               }
+                                       });
                                }
                        });