Working around some new bugs ;)
authorAlexander Ebert <ebert@woltlab.com>
Tue, 25 Oct 2016 14:18:34 +0000 (16:18 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 25 Oct 2016 14:18:41 +0000 (16:18 +0200)
com.woltlab.wcf/templates/wysiwyg.tpl
wcfsetup/install/files/acp/templates/wysiwyg.tpl
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabClean.js
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabList.js [deleted file]

index d6576ff48f7a0325de97d26d9b8591f711d4a5a3..2435b9a804eaf4576c0a9d42058399d6b953c0da 100644 (file)
@@ -26,7 +26,6 @@
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabInsert.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabKeydown.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabLink.js?v={@LAST_UPDATE_TIME}',
-                       '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabList.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMedia.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMention.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabModal.js?v={@LAST_UPDATE_TIME}',
                                        'WoltLabInlineCode',
                                        'WoltLabInsert',
                                        'WoltLabLink',
-                                       'WoltLabList',
                                        'WoltLabModal',
                                        'WoltLabObserve',
                                        'WoltLabPaste',
index d6576ff48f7a0325de97d26d9b8591f711d4a5a3..2435b9a804eaf4576c0a9d42058399d6b953c0da 100644 (file)
@@ -26,7 +26,6 @@
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabInsert.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabKeydown.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabLink.js?v={@LAST_UPDATE_TIME}',
-                       '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabList.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMedia.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabMention.js?v={@LAST_UPDATE_TIME}',
                        '{@$__wcf->getPath()}js/3rdParty/redactor2/plugins/WoltLabModal.js?v={@LAST_UPDATE_TIME}',
                                        'WoltLabInlineCode',
                                        'WoltLabInsert',
                                        'WoltLabLink',
-                                       'WoltLabList',
                                        'WoltLabModal',
                                        'WoltLabObserve',
                                        'WoltLabPaste',
index 0fe2d1766b9e324b7a11cdfb340eb35eaecfe634..31cdce6da915279d2f0864f6383483abcde49162 100644 (file)
@@ -196,7 +196,7 @@ $.Redactor.prototype.WoltLabClean = function() {
                        this.clean.convertTags = (function(html, data) {
                                var div = elCreate('div');
                                div.innerHTML = html;
-                               
+                               console.debug(html);
                                // reset tag storage
                                storage = [];
                                
@@ -213,7 +213,45 @@ $.Redactor.prototype.WoltLabClean = function() {
                                        item.element.outerHTML = '###custom' + i + '###' + item.element.innerHTML + '###/custom' + i + '###';
                                });
                                
-                               return mpConvertTags.call(this, div.innerHTML, data);
+                               var hadLinks = false;
+                               if (data.links && this.opts.pasteLinks) {
+                                       elBySelAll('a', div, function(link) {
+                                               if (link.href) {
+                                                       link.outerHTML = '##%a href="' + link.href + '"%##' + link.innerHTML + '##%/a%##';
+                                               }
+                                       });
+                                       
+                                       hadLinks = true;
+                                       data.links = false;
+                               }
+                               
+                               var hadImages = false;
+                               if (data.images && this.opts.pasteImages) {
+                                       elBySelAll('img', div, function(image) {
+                                               if (image.src) {
+                                                       var tmp = '##%img src="' + image.src + '"';
+                                                       var attr;
+                                                       for (var j = 0, length = image.attributes.length; j < length; j++) {
+                                                               attr = image.attributes.item(j);
+                                                               if (attr.name !== 'src') {
+                                                                       tmp += ' ' + attr.name + '="' + attr.value + '"';
+                                                               }
+                                                       }
+                                                       
+                                                       image.outerHTML = tmp + '%##';
+                                               }
+                                       });
+                                       
+                                       hadImages = true;
+                                       data.images = false;
+                               }
+                               
+                               html = mpConvertTags.call(this, div.innerHTML, data);
+                               
+                               if (hadImages) data.images = true;
+                               if (hadLinks) data.links = true;
+                               
+                               return html;
                        }).bind(this);
                        
                        var mpReconvertTags = this.clean.reconvertTags;
@@ -248,49 +286,6 @@ $.Redactor.prototype.WoltLabClean = function() {
                                        html = div.innerHTML;
                                }
                                
-                               // reconvert links as the regex can be overly greedy sometimes
-                               if (data.links) {
-                                       // prevent the original regex from being executed again
-                                       data.links = false;
-                                       
-                                       // We try to avoid the regex to consume too many parts
-                                       // by having it work from the back to the front. Please
-                                       // keep in mind that the parts are reversed, so they
-                                       // actually appear in inverted order
-                                       var tmp = html.split(/(###\/a###)/gi).reverse();
-                                       var part, nextPart;
-                                       for (var i = 1, length = tmp.length; i < length; i++) {
-                                               if (i + 1 === length) {
-                                                       break;
-                                               }
-                                               
-                                               part = tmp[i];
-                                               nextPart = tmp[i + 1];
-                                               
-                                               // split by '###a' to find all possible start positions
-                                               var anchors = nextPart.split(/(###a)/gi).reverse();
-                                               var composite;
-                                               for (var j = 1, innerLength = anchors.length; j < innerLength; j++) {
-                                                       if (j + 1 === innerLength) {
-                                                               break;
-                                                       }
-                                                       
-                                                       composite = anchors[j] + anchors[j - 1];
-                                                       if (composite.match(/###a(.*?)href="(.*?)"(.*?)###(.*?)/i)) {
-                                                               anchors[j] = '';
-                                                               anchors[j - 1] = composite.replace(/###a(.*?)href="(.*?)"(.*?)###(.*?)/i, '<a$1href="$2"$3>$4');
-                                                               
-                                                               tmp[i] = '</a>';
-                                                               tmp[i + 1] = anchors.reverse().join('');
-                                                               
-                                                               break;
-                                                       }
-                                               }
-                                       }
-                                       
-                                       html = tmp.reverse().join('');
-                               }
-                               
                                return mpReconvertTags.call(this, html, data);
                        }).bind(this);
                        
diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabList.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabList.js
deleted file mode 100644 (file)
index 8d61cba..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-$.Redactor.prototype.WoltLabList = function() {
-       "use strict";
-       
-       return {
-               init: function () {
-                       this.list.combineAfterAndBefore = (function (block) {
-                               var $prev = $(block).prev();
-                               var $next = $(block).next();
-                               var isEmptyBlock = (block && block.tagName === 'P' && (block.innerHTML === '<br>' || block.innerHTML === ''));
-                               
-                               // WoltLab fix: closest() was missing the 2nd parameter causing
-                               // it to match on lists being Redactor's ancestor
-                               var isBlockWrapped = ($prev.closest('ol, ul', this.core.editor()[0]).length === 1 && $next.closest('ol, ul', this.core.editor()[0]).length === 1);
-                               
-                               if (isEmptyBlock && isBlockWrapped)
-                               {
-                                       $prev.children('li').last().append(this.marker.get());
-                                       $prev.append($next.contents());
-                                       this.selection.restore();
-                                       
-                                       return true;
-                               }
-                               
-                               return false;
-                       }).bind(this);
-               }
-       };
-};