Improved detection of HTML images pasted in Chrome
authorAlexander Ebert <ebert@woltlab.com>
Thu, 26 Oct 2017 14:11:44 +0000 (16:11 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 26 Oct 2017 14:11:44 +0000 (16:11 +0200)
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabPaste.js

index 501487f4384b5b9d56abf8bc8aad48d35bb77dc5..66056bd087ac5fd1b620c6d059c977e085e4bba6 100644 (file)
@@ -62,7 +62,7 @@ $.Redactor.prototype.WoltLabPaste = function() {
                                                
                                                // remove document fragments
                                                if (pastedHtml.match(/^<html>[\s\S]*?<body>([\s\S]+)<\/body>\s*<\/html>$/)) {
-                                                       pastedHtml = RegExp.$1;
+                                                       pastedHtml = RegExp.$1.replace(/^\s*(?:<!--StartFragment-->)(.+)(?:<!--EndFragment-->)?\s*$/, '$1');
                                                }
                                        }
                                }
@@ -168,6 +168,20 @@ $.Redactor.prototype.WoltLabPaste = function() {
                                                return;
                                        }
                                        
+                                       if (this.detect.isWebkit()) {
+                                               var item, hasFile = false, hasHtml = false;
+                                               for (var i = 0, length = clipboard.items.length; i < length; i++) {
+                                                       item = clipboard.items[i];
+                                                       if (item.kind === 'string' && item.type === 'text/html') hasHtml = true;
+                                                       else if (item.kind === 'file') hasFile = true;
+                                               }
+                                               
+                                               // pasted an `<img>` element from clipboard
+                                               if (hasFile && hasHtml) {
+                                                       return false;
+                                               }
+                                       }
+                                       
                                        var cancelPaste = false;
                                        file = clipboard.items[0].getAsFile();
                                        if (file === null) {