From 5a761a498476556963eaafd24212f62f9110e5a0 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 27 Jul 2014 15:38:14 +0200 Subject: [PATCH] Fixed a few issues with embedded attachments and extended edit --- .../js/3rdParty/redactor/plugins/wbbcode.js | 39 +++++++++++++++++-- .../js/3rdParty/redactor/plugins/wutil.js | 1 + wcfsetup/install/files/js/WCF.Attachment.js | 15 +++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index 96c9c761d0..ce62f6d1d1 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -531,8 +531,16 @@ RedactorPlugins.wbbcode = { // attachments var $attachmentUrl = this.getOption('wAttachmentUrl'); if ($attachmentUrl) { - data = data.replace(/\[attach=(\d+)\]\[\/attach\]/, function(match, attachmentID) { - return ''; + var $imageAttachmentIDs = this._getImageAttachmentIDs(); + + data = data.replace(/\[attach=(\d+)\]\[\/attach\]/g, function(match, attachmentID) { + attachmentID = parseInt(attachmentID); + + if (WCF.inArray(attachmentID, $imageAttachmentIDs)) { + return ''; + } + + return match; }); } @@ -657,10 +665,13 @@ RedactorPlugins.wbbcode = { * @param integer attachmentID */ insertAttachment: function(attachmentID) { + attachmentID = parseInt(attachmentID); var $attachmentUrl = this.getOption('wAttachmentUrl'); var $bbcode = '[attach=' + attachmentID + '][/attach]'; - if ($attachmentUrl) { + var $imageAttachmentIDs = this._getImageAttachmentIDs(); + + if ($attachmentUrl && WCF.inArray(attachmentID, $imageAttachmentIDs)) { this.insertDynamic( '', $bbcode @@ -669,5 +680,27 @@ RedactorPlugins.wbbcode = { else { this.insertDynamic($bbcode); } + }, + + /** + * Returns a list of attachments representing an image. + * + * @return array + */ + _getImageAttachmentIDs: function() { + // WCF.Attachment.Upload may have no been initialized yet, fallback to static data + var $imageAttachmentIDs = this.getOption('wAttachmentImageIDs') || [ ]; + if ($imageAttachmentIDs.length) { + delete this.opts.wAttachmentImageIDs; + + return $imageAttachmentIDs; + } + + var $data = { + imageAttachmentIDs: [ ] + }; + WCF.System.Event.fireEvent('com.woltlab.wcf.redactor', 'getImageAttachments_' + this.$source.wcfIdentify(), $data); + + return $data.imageAttachmentIDs; } }; diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js index 487da18005..924698a3d8 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wutil.js @@ -304,6 +304,7 @@ RedactorPlugins.wutil = { * Synchronizes editor's source textarea. */ wSync: function() { + this.sync(); this.$source.val(this.cleanHtml(this.$source.val())); this._convertFromHtml(); } diff --git a/wcfsetup/install/files/js/WCF.Attachment.js b/wcfsetup/install/files/js/WCF.Attachment.js index b1ed25edb4..2acaf7158e 100644 --- a/wcfsetup/install/files/js/WCF.Attachment.js +++ b/wcfsetup/install/files/js/WCF.Attachment.js @@ -82,6 +82,7 @@ WCF.Attachment.Upload = WCF.Upload.extend({ WCF.System.Event.addListener('com.woltlab.wcf.messageOptionsInline', 'submit_' + this._wysiwygContainerID, $.proxy(this._submitInline, this)); WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'reset', $.proxy(this._reset, this)); WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'upload_' + this._wysiwygContainerID, $.proxy(this._editorUpload, this)); + WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'getImageAttachments_' + this._wysiwygContainerID, $.proxy(this._getImageAttachments, this)); } }, @@ -108,6 +109,20 @@ WCF.Attachment.Upload = WCF.Upload.extend({ data.uploadID = $uploadID; }, + /** + * Sets the attachment ids representing an image. + * + * @param object data + */ + _getImageAttachments: function(data) { + this._fileListSelector.children('li').each(function(index, attachment) { + var $attachment = $(attachment); + if ($attachment.children('img.attachmentTinyThumbnail').length) { + data.imageAttachmentIDs.push($attachment.data('objectID')); + } + }); + }, + /** * Adds parameters for the inline editor. * -- 2.20.1