From a9255db0a58b3f3c6141ccb84c9982ac5c9e17f7 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 10 Oct 2016 10:02:35 +0200 Subject: [PATCH] Fixed metacode handling and embedded media --- com.woltlab.wcf/templates/wysiwyg.tpl | 6 ++-- .../install/files/acp/templates/wysiwyg.tpl | 6 ++-- .../redactor2/plugins/WoltLabMedia.js | 34 +++++++++++++++++++ wcfsetup/install/files/js/WCF.Attachment.js | 4 +-- .../WoltLabSuite/Core/Ui/Redactor/Metacode.js | 5 +-- .../js/WoltLabSuite/Core/Ui/Redactor/Quote.js | 3 +- 6 files changed, 49 insertions(+), 9 deletions(-) diff --git a/com.woltlab.wcf/templates/wysiwyg.tpl b/com.woltlab.wcf/templates/wysiwyg.tpl index 2afb6a18e0..79d502e73f 100644 --- a/com.woltlab.wcf/templates/wysiwyg.tpl +++ b/com.woltlab.wcf/templates/wysiwyg.tpl @@ -107,7 +107,6 @@ {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) { @@ -215,7 +214,8 @@ buttons: buttonOptions, buttonMobile: buttonMobile, customButtons: customButtons, - highlighters: highlighters + highlighters: highlighters, + mediaUrl: '{link controller='Media' id=-123456789 thumbnail='void' forceFrontend=true}{/link}' } }; @@ -249,6 +249,8 @@ content = '


'; } + content = UiRedactorMetacode.convertFromHtml(element.id, content); + var redactor = $(element).data('redactor'); // set code diff --git a/wcfsetup/install/files/acp/templates/wysiwyg.tpl b/wcfsetup/install/files/acp/templates/wysiwyg.tpl index 2afb6a18e0..79d502e73f 100644 --- a/wcfsetup/install/files/acp/templates/wysiwyg.tpl +++ b/wcfsetup/install/files/acp/templates/wysiwyg.tpl @@ -107,7 +107,6 @@ {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) { @@ -215,7 +214,8 @@ buttons: buttonOptions, buttonMobile: buttonMobile, customButtons: customButtons, - highlighters: highlighters + highlighters: highlighters, + mediaUrl: '{link controller='Media' id=-123456789 thumbnail='void' forceFrontend=true}{/link}' } }; @@ -249,6 +249,8 @@ content = '


'; } + content = UiRedactorMetacode.convertFromHtml(element.id, content); + var redactor = $(element).data('redactor'); // set code diff --git a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabMedia.js b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabMedia.js index bac860718f..a2ff5def1a 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabMedia.js +++ b/wcfsetup/install/files/js/3rdParty/redactor2/plugins/WoltLabMedia.js @@ -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 diff --git a/wcfsetup/install/files/js/WCF.Attachment.js b/wcfsetup/install/files/js/WCF.Attachment.js index e40c1033a1..9a62468602 100644 --- a/wcfsetup/install/files/js/WCF.Attachment.js +++ b/wcfsetup/install/files/js/WCF.Attachment.js @@ -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)); } }, diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Metacode.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Metacode.js index 48eebcf410..0123118aa2 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Metacode.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Metacode.js @@ -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; } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js index 722c91baad..534790b522 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js @@ -85,7 +85,8 @@ define(['Core', 'EventHandler', 'EventKey', 'Language', 'StringUtil', 'Dom/Util' content = content.replace(/\n/g, '
'); } 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 -- 2.20.1