From 31bec02cffd6f9e2055fcd3ef9753f787438792f Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 26 Nov 2014 02:09:43 +0100 Subject: [PATCH] Removing embedded attachments upon delete from WYSIWYG view --- .../js/3rdParty/redactor/plugins/wbbcode.js | 19 ++++++++++++++++++ wcfsetup/install/files/js/WCF.Attachment.js | 20 +++++++++---------- wcfsetup/install/files/js/WCF.js | 16 +++++++++++---- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js index 671197ef3e..c2d4e60175 100644 --- a/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js +++ b/wcfsetup/install/files/js/3rdParty/redactor/plugins/wbbcode.js @@ -1095,6 +1095,25 @@ RedactorPlugins.wbbcode = function() { } }, + /** + * Removes an attachment from WYSIWYG view. + * + * @param integer attachmentID + */ + removeAttachment: function(attachmentID) { + if (!this.opts.visual) { + // we're not going to mess with the code view + return; + } + + this.$editor.find('img.redactorEmbeddedAttachment').each(function(index, attachment) { + var $attachment = $(attachment); + if ($attachment.data('attachmentID') == attachmentID) { + $attachment.remove(); + } + }); + }, + /** * Returns a list of attachments representing an image. * diff --git a/wcfsetup/install/files/js/WCF.Attachment.js b/wcfsetup/install/files/js/WCF.Attachment.js index 59040dcfe9..b96cc4974f 100644 --- a/wcfsetup/install/files/js/WCF.Attachment.js +++ b/wcfsetup/install/files/js/WCF.Attachment.js @@ -58,7 +58,7 @@ WCF.Attachment.Upload = WCF.Upload.extend({ */ init: function(buttonSelector, fileListSelector, objectType, objectID, tmpHash, parentObjectID, maxUploads, wysiwygContainerID) { this._super(buttonSelector, fileListSelector, 'wcf\\data\\attachment\\AttachmentAction', { multiple: true, maxUploads: maxUploads }); - console.debug(wysiwygContainerID); + this._autoInsert = [ ]; this._objectType = objectType; this._objectID = objectID; @@ -71,7 +71,8 @@ WCF.Attachment.Upload = WCF.Upload.extend({ this._fileListSelector.find('.jsButtonAttachmentInsertThumbnail').click($.proxy(this._insert, this)); this._fileListSelector.find('.jsButtonAttachmentInsertFull').click($.proxy(this._insert, this)); - WCF.DOMNodeRemovedHandler.addCallback('WCF.Attachment.Upload', $.proxy(this._removeLimitError, this)); + //WCF.DOMNodeRemovedHandler.addCallback('WCF.Attachment.Upload', $.proxy(this._removeLimitError, this)); + WCF.System.Event.addListener('com.woltlab.wcf.action.delete', 'attachment_' + this._wysiwygContainerID, $.proxy(this._removeLimitError, this)); this._makeSortable(); @@ -181,14 +182,9 @@ WCF.Attachment.Upload = WCF.Upload.extend({ /** * Removes the limit error message. * - * @param object event + * @param object data */ - _removeLimitError: function(event) { - var $target = $(event.target); - if ($target.is('li.box48') && $target.parent().wcfIdentify() === this._fileListSelector.wcfIdentify()) { - this._buttonSelector.next('small.innerError').remove(); - } - + _removeLimitError: function(data) { var $listItems = this._fileListSelector.children('li'); if (!$listItems.filter(':not(.uploadFailed)').length) { this._insertAllButton.hide(); @@ -199,6 +195,10 @@ WCF.Attachment.Upload = WCF.Upload.extend({ this._fileListSelector.wcfBlindOut(); }).bind(this), 250); } + + if (this._wysiwygContainerID) { + $('#' + this._wysiwygContainerID).redactor('wbbcode.removeAttachment', data.button.data('objectID')); + } }, /** @@ -308,7 +308,7 @@ WCF.Attachment.Upload = WCF.Upload.extend({ // init buttons var $buttonList = $li.find('ul').addClass('buttonGroup'); - var $deleteButton = $('
  • ' + WCF.Language.get('wcf.global.button.delete') + '
  • '); + var $deleteButton = $('
  • ' + WCF.Language.get('wcf.global.button.delete') + '
  • '); $buttonList.append($deleteButton); $li.data('objectID', data.returnValues.attachments[$internalFileID].attachmentID); diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 2e8d325066..19c91e621a 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -2519,12 +2519,20 @@ WCF.Action.Delete = Class.extend({ triggerEffect: function(objectIDs) { for (var $index in this._containers) { var $container = $('#' + this._containers[$index]); - if (WCF.inArray($container.find(this._buttonSelector).data('objectID'), objectIDs)) { + var $button = $container.find(this._buttonSelector); + if (WCF.inArray($button.data('objectID'), objectIDs)) { var self = this; $container.wcfBlindOut('up',function() { - $(this).remove(); - self._containers.splice(self._containers.indexOf($(this).wcfIdentify()), 1); - self._didTriggerEffect($(this)); + var $container = $(this).remove(); + self._containers.splice(self._containers.indexOf($container.wcfIdentify()), 1); + self._didTriggerEffect($container); + + if ($button.data('eventName')) { + WCF.System.Event.fireEvent('com.woltlab.wcf.action.delete', $button.data('eventName'), { + button: $button, + container: $container + }); + } }); } } -- 2.20.1