Detection of pasted blob uris in iOS
authorAlexander Ebert <ebert@woltlab.com>
Fri, 9 Apr 2021 16:48:41 +0000 (18:48 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 9 Apr 2021 16:48:41 +0000 (18:48 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabPaste.js
wcfsetup/install/files/js/WoltLabSuite/Core/FileUtil.js

index beebe1dec7dfe1291df3d8681bd37d0747483440..d97b619f26d9e13d4d2c4169b5b507cf389d9224 100644 (file)
@@ -351,7 +351,7 @@ $.Redactor.prototype.WoltLabPaste = function() {
                                if (!data.pre && !data.text) {
                                        elBySelAll('img', div, (function(img) {
                                                var src = img.src;
-                                               if (src.indexOf('data:image') === 0 && src !== transparentGif) {
+                                               if ((src.indexOf('data:image') === 0 | src.indexOf("blob:") === 0) && src !== transparentGif) {
                                                        img.src = transparentGif;
                                                        
                                                        var uuid = WCF.getUUID();
@@ -397,10 +397,24 @@ $.Redactor.prototype.WoltLabPaste = function() {
                                                                        img.parentNode.removeChild(img);
                                                                }
                                                                else {
-                                                                       WCF.System.Event.fireEvent('com.woltlab.wcf.redactor2', 'pasteFromClipboard_' + this.$element[0].id, {
-                                                                               blob: this.utils.dataURItoBlob(imgData.src),
-                                                                               replace: img
-                                                                       });
+                                                                       if (imgData.src.indexOf("blob:") === 0) {
+                                                                               window.fetch(imgData.src)
+                                                                                       .then(function (response) {
+                                                                                               return response.blob();
+                                                                                       })
+                                                                                       .then((function (blob) {
+                                                                                               WCF.System.Event.fireEvent('com.woltlab.wcf.redactor2', 'pasteFromClipboard_' + this.$element[0].id, {
+                                                                                                       blob: blob,
+                                                                                                       replace: img
+                                                                                               });
+                                                                                       }).bind(this));
+                                                                       }
+                                                                       else {
+                                                                               WCF.System.Event.fireEvent('com.woltlab.wcf.redactor2', 'pasteFromClipboard_' + this.$element[0].id, {
+                                                                                       blob: this.utils.dataURItoBlob(imgData.src),
+                                                                                       replace: img
+                                                                               });
+                                                                       }
                                                                }
                                                        }
                                                }
index a7390b3cedfe9a3d7417920ff10d6d275f4bff7f..d356f98914cc3b6de37219007864a845a2faa0ec 100644 (file)
@@ -122,7 +122,13 @@ define(['Dictionary', 'StringUtil'], function(Dictionary, StringUtil) {
                // word
                'application/msword': 'doc',
                'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',
-               'application/vnd.oasis.opendocument.text': 'odt'
+               'application/vnd.oasis.opendocument.text': 'odt',
+
+               // iOS
+               'public.jpeg': 'jpeg',
+               'public.png': 'png',
+               'com.compuserve.gif': 'gif',
+               'org.webmproject.webp': 'webp'
        });
        
        return {