// attachments
var $attachmentUrl = this.getOption('wAttachmentUrl');
if ($attachmentUrl) {
- data = data.replace(/\[attach=(\d+)\]\[\/attach\]/, function(match, attachmentID) {
- return '<img src="' + $attachmentUrl.replace(/987654321/, attachmentID) + '" class="redactorEmbeddedAttachment" data-attachment-id="' + attachmentID + '" />';
+ var $imageAttachmentIDs = this._getImageAttachmentIDs();
+
+ data = data.replace(/\[attach=(\d+)\]\[\/attach\]/g, function(match, attachmentID) {
+ attachmentID = parseInt(attachmentID);
+
+ if (WCF.inArray(attachmentID, $imageAttachmentIDs)) {
+ return '<img src="' + $attachmentUrl.replace(/987654321/, attachmentID) + '" class="redactorEmbeddedAttachment" data-attachment-id="' + attachmentID + '" />';
+ }
+
+ return match;
});
}
* @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(
'<img src="' + $attachmentUrl.replace(/987654321/, attachmentID) + '" class="redactorEmbeddedAttachment" data-attachment-id="' + attachmentID + '" />',
$bbcode
else {
this.insertDynamic($bbcode);
}
+ },
+
+ /**
+ * Returns a list of attachments representing an image.
+ *
+ * @return array<integer>
+ */
+ _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;
}
};
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));
}
},
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.
*