Fixed metacode handling and embedded media
authorAlexander Ebert <ebert@woltlab.com>
Mon, 10 Oct 2016 08:02:35 +0000 (10:02 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 10 Oct 2016 08:02:35 +0000 (10:02 +0200)
com.woltlab.wcf/templates/wysiwyg.tpl
wcfsetup/install/files/acp/templates/wysiwyg.tpl
wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabMedia.js
wcfsetup/install/files/js/WCF.Attachment.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Metacode.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js

index 2afb6a18e03984666407538c33fc4f448cab9fc4..79d502e73f847c564c403dc1c9aa56eca49c08c7 100644 (file)
                        {include file='mediaJavaScript'}
                        
                        var element = elById('{if $wysiwygSelector|isset}{$wysiwygSelector|encodeJS}{else}text{/if}');
-                       UiRedactorMetacode.convert(element);
                        
                        var autosave = elData(element, 'autosave') || null;
                        if (autosave) {
                                        buttons: buttonOptions,
                                        buttonMobile: buttonMobile,
                                        customButtons: customButtons,
-                                       highlighters: highlighters
+                                       highlighters: highlighters,
+                                       mediaUrl: '{link controller='Media' id=-123456789 thumbnail='void' forceFrontend=true}{/link}'
                                }
                        };
                        
                                                content = '<p><br></p>';
                                        }
                                        
+                                       content = UiRedactorMetacode.convertFromHtml(element.id, content);
+                                       
                                        var redactor = $(element).data('redactor');
                                        
                                        // set code
index 2afb6a18e03984666407538c33fc4f448cab9fc4..79d502e73f847c564c403dc1c9aa56eca49c08c7 100644 (file)
                        {include file='mediaJavaScript'}
                        
                        var element = elById('{if $wysiwygSelector|isset}{$wysiwygSelector|encodeJS}{else}text{/if}');
-                       UiRedactorMetacode.convert(element);
                        
                        var autosave = elData(element, 'autosave') || null;
                        if (autosave) {
                                        buttons: buttonOptions,
                                        buttonMobile: buttonMobile,
                                        customButtons: customButtons,
-                                       highlighters: highlighters
+                                       highlighters: highlighters,
+                                       mediaUrl: '{link controller='Media' id=-123456789 thumbnail='void' forceFrontend=true}{/link}'
                                }
                        };
                        
                                                content = '<p><br></p>';
                                        }
                                        
+                                       content = UiRedactorMetacode.convertFromHtml(element.id, content);
+                                       
                                        var redactor = $(element).data('redactor');
                                        
                                        // set code
index bac860718fcfd1103d6392bf1d2d857a4cf36760..a2ff5def1a30547592054a1c09816186c3f99442 100644 (file)
@@ -6,6 +6,40 @@ $.Redactor.prototype.WoltLabMedia = function() {
                        var button = this.button.add('woltlabMedia', '');
                        $(button).addClass('jsMediaEditorButton');
                        
+                       var metacodeUuid = WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'metacode_wsm_' + this.$element[0].id, (function(data) {
+                               if (data.attributes.length === 1) {
+                                       // ignore non-image files
+                                       return;
+                               }
+                               
+                               var float = '';
+                               if (data.attributes === 3) {
+                                       if (data.attributes[2] === 'left') {
+                                               float = ' messageFloatObjectLeft';
+                                       }
+                                       else if (data.attributes[2] === 'right') {
+                                               float = ' messageFloatObjectRight';
+                                       }
+                               }
+                               
+                               var image = elCreate('img');
+                               image.className = 'woltlabSuiteMedia' + float;
+                               //noinspection JSUnresolvedVariable
+                               image.src = this.opts.woltlab.mediaUrl.replace('-123456789', data.attributes[0]).replace('thumbnail=void', 'thumbnail=' + data.attributes[1]);
+                               elData(image, 'media-id', data.attributes[0]);
+                               elData(image, 'media-size', data.attributes[1]);
+                               
+                               var metacode = data.metacode;
+                               metacode.parentNode.insertBefore(image, metacode);
+                               elRemove(metacode);
+                               
+                               data.cancel = true;
+                       }).bind(this));
+                       
+                       WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'destroy_' + this.$element[0].id, (function () {
+                               WCF.System.Event.removeListener('com.woltlab.wcf.redactor2', 'metacode_wsm_' + this.$element[0].id, metacodeUuid);
+                       }).bind(this));
+                       
                        require(['WoltLabSuite/Core/Media/Manager/Editor'], function(MediaManagerEditor) {
                                new MediaManagerEditor({
                                        editor: this
index e40c1033a1df9d471208ed95bd0798753e4faa42..9a6246860238ef23a2e63dc294e44691d0c27f2e 100644 (file)
@@ -95,7 +95,7 @@ WCF.Attachment.Upload = WCF.Upload.extend({
                        WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'dragAndDrop_' + this._editorId, this._editorUpload.bind(this));
                        WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'pasteFromClipboard_' + this._editorId, this._editorUpload.bind(this));
                        
-                       var metacodeAttachUuid = WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'metacode_attach', (function(data) {
+                       var metacodeAttachUuid = WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'metacode_attach_' + this._editorId, (function(data) {
                                var images = this._getImageAttachments();
                                var attachmentId = data.attributes[0] || 0;
                                if (images.hasOwnProperty(attachmentId)) {
@@ -126,7 +126,7 @@ WCF.Attachment.Upload = WCF.Upload.extend({
                                WCF.System.Event.removeAllListeners('com.woltlab.wcf.redactor2', 'dragAndDrop_' + this._editorId);
                                WCF.System.Event.removeAllListeners('com.woltlab.wcf.redactor2', 'pasteFromClipboard_' + this._editorId);
                                
-                               WCF.System.Event.removeListener('com.woltlab.wcf.redactor2', 'metacode_attach', metacodeAttachUuid);
+                               WCF.System.Event.removeListener('com.woltlab.wcf.redactor2', 'metacode_attach_' + this._editorId, metacodeAttachUuid);
                        }).bind(this));
                }
        },
index 48eebcf410293df85818193a24d4bcaa04c4fcd0..0123118aa2a9d2870e9282aebf52c74d66a8d302 100644 (file)
@@ -22,7 +22,7 @@ define(['EventHandler', 'Dom/Util'], function(EventHandler, DomUtil) {
                        element.textContent = this.convertFromHtml(element.textContent);
                },
                
-               convertFromHtml: function (html) {
+               convertFromHtml: function (editorId, html) {
                        var div = elCreate('div');
                        div.innerHTML = html;
                        
@@ -37,7 +37,8 @@ define(['EventHandler', 'Dom/Util'], function(EventHandler, DomUtil) {
                                        cancel: false,
                                        metacode: metacode
                                };
-                               EventHandler.fire('com.woltlab.wcf.redactor2', 'metacode_' + name, data);
+                               
+                               EventHandler.fire('com.woltlab.wcf.redactor2', 'metacode_' + name + '_' + editorId, data);
                                if (data.cancel === true) {
                                        continue;
                                }
index 722c91baadc00660a3f1c46966e9ded8e603f005..534790b52276eb71f006aa496b0a95c4e6c4a53c 100644 (file)
@@ -85,7 +85,8 @@ define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util'
                                content = content.replace(/\n/g, '<br>');
                        }
                        else {
-                               content = UiRedactorMetacode.convertFromHtml(content);
+                               //noinspection JSUnresolvedFunction
+                               content = UiRedactorMetacode.convertFromHtml(this._editor.$element[0].id, content);
                        }
                        
                        // bypass the editor as `insert.html()` doesn't like us