var config = {
buttons: buttons,
- clipboardImageUpload: false,
+ clipboardImageUpload: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('img')}true{else}false{/if},
formatting: ['p', 'h2', 'h3', 'h4'],
imageCaption: false,
+ imageUpload: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('img')}true{else}false{/if},
lang: 'wsc', // fake language to offload phrases
langs: {
wsc: {
linkify: false,
linkSize: 0xBADC0DED, // some random value to disable truncating
minHeight: 200,
- pasteImages: false,
+ pasteImages: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('img')}true{else}false{/if},
plugins: [
// Imperavi
'alignment',
return {
init: function() {
require(['EventHandler'], (function(EventHandler) {
- EventHandler.add('com.woltlab.wcf.redactor2', 'insertAttachment_' + this.$element[0].id, this.WoltLabAttachment._insert.bind(this))
- EventHandler.add('com.woltlab.wcf.redactor2', 'deleteAttachment_' + this.$element[0].id, this.WoltLabAttachment._delete.bind(this))
+ EventHandler.add('com.woltlab.wcf.redactor2', 'insertAttachment_' + this.$element[0].id, this.WoltLabAttachment._insert.bind(this));
+ EventHandler.add('com.woltlab.wcf.redactor2', 'deleteAttachment_' + this.$element[0].id, this.WoltLabAttachment._delete.bind(this));
+ EventHandler.add('com.woltlab.wcf.redactor2', 'replaceAttachment_' + this.$element[0].id, this.WoltLabAttachment._replaceAttachment.bind(this));
}).bind(this));
},
// non-image attachment
this.insert.text('[attach=' + attachmentId + '][/attach]');
}
+
+ this.buffer.set();
+ },
+
+ _replaceAttachment: function (data) {
+ var img = elCreate('img');
+ img.className = 'woltlabAttachment';
+ img.src = data.src;
+ elData(img, 'attachment-id', data.attachmentId);
+
+ data.img.parentNode.insertBefore(img, data.img);
+ elRemove(data.img);
},
_delete: function(data) {
close: function() {
this.selection.restore();
- _uiDialog.close(this);
+ // avoid calling `close()` without any dialogs opened before
+ if (_uiDialog.getDialog(this)) {
+ _uiDialog.close(this);
+ }
},
load: function(templateName, title) {
// rebind paste event
this.core.editor().off('paste.redactor').on('paste.redactor', this.paste.init.bind(this));
+
+ this.paste.detectClipboardUpload = (function (e) {
+ e = e.originalEvent || e;
+
+ var clipboard = e.clipboardData;
+
+ // WoltLab modification: allow Edge
+ if (this.detect.isIe() && (this.detect.isIe() !== 'edge' || document.documentMode))
+ {
+ return true;
+ }
+
+ if (this.detect.isFirefox())
+ {
+ return false;
+ }
+
+ // prevent safari fake url
+ var types = clipboard.types;
+ // WoltLab modification: `DataTransfer.types` is a `DOMStringList` in Edge
+ if (Array.isArray(types) && types.indexOf('public.tiff') !== -1)
+ {
+ e.preventDefault();
+ return false;
+ }
+
+
+ if (!clipboard.items || !clipboard.items.length)
+ {
+ return;
+ }
+
+ var file = clipboard.items[0].getAsFile();
+ if (file === null)
+ {
+ return false;
+ }
+
+ var reader = new FileReader();
+ reader.readAsDataURL(file);
+ reader.onload = $.proxy(this.paste.insertFromClipboard, this);
+
+ return true;
+ }).bind(this);
+
+ this.paste.insertFromClipboard = (function (e) {
+ if (!window.FormData) {
+ return;
+ }
+
+ this.buffer.set();
+
+ WCF.System.Event.fireEvent('com.woltlab.wcf.redactor2', 'pasteFromClipboard_' + this.$element[0].id, {
+ blob: this.utils.dataURItoBlob(e.target.result)
+ });
+ }).bind(this);
+
+ this.paste.clipboardUpload = (function () {
+ elBySelAll('img', this.$editor[0], (function (img) {
+ if (!window.FormData || img.src.indexOf('data:image') !== 0) {
+ return;
+ }
+
+ this.buffer.set();
+
+ elHide(img);
+
+ WCF.System.Event.fireEvent('com.woltlab.wcf.redactor2', 'pasteFromClipboard_' + this.$element[0].id, {
+ blob: this.utils.dataURItoBlob(img.src),
+ replace: img
+ });
+ }).bind(this));
+ }).bind(this);
+
+ var mpInsert = this.paste.insert;
+ this.paste.insert = (function(html, data) {
+ if (!data.pre && !data.text) {
+ var div = elCreate('div');
+ div.innerHTML = html;
+
+ elBySelAll('img', this.$editor[0], function (img) {
+ if (img.src.indexOf('data:image') === 0) {
+ elHide(img);
+ }
+ });
+
+ html = div.innerHTML;
+ }
+
+ mpInsert.call(this, html, data);
+ }).bind(this);
}
};
};
*/
_editorId: '',
+ /**
+ * replace img element on load
+ * @var Object
+ */
+ _replaceOnLoad: {},
+
/**
* @see WCF.Upload.init()
*/
WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'submit_' + this._editorId, this._submitInline.bind(this));
WCF.System.Event.addListener('com.woltlab.wcf.redactor2', 'reset_' + this._editorId, this._reset.bind(this));
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 images = this._getImageAttachments();
WCF.System.Event.removeAllListeners('com.woltlab.wcf.redactor2', 'reset_' + this._editorId);
WCF.System.Event.removeAllListeners('com.woltlab.wcf.redactor2', 'insertAttachment_' + this._editorId);
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);
}).bind(this));
* @param object data
*/
_editorUpload: function(data) {
- var $uploadID;
+ var $uploadID, replace = null;
// show tab
this._fileListSelector.closest('.messageTabMenu').messageTabMenu('showTab', 'attachments', true);
}
else {
$uploadID = this._upload(undefined, undefined, data.blob);
+ replace = data.replace || null;
+ }
+
+ if (replace === null) {
+ this._autoInsert.push($uploadID);
+ }
+ else {
+ this._replaceOnLoad[$uploadID] = replace;
}
- this._autoInsert.push($uploadID);
data.uploadID = $uploadID;
},
}
if (!$listItems.length) {
- setTimeout((function() {
- this._fileListSelector.wcfBlindOut();
- }).bind(this), 250);
+ this._fileListSelector.hide();
}
if (this._editorId && data.button) {
$insertPlain.appendTo($buttonList).children('span.button').click($.proxy(this._insert, this));
}
}
+
+ if (this._replaceOnLoad.hasOwnProperty(uploadID)) {
+ if (!$li.hasClass('uploadFailed')) {
+ var img = this._replaceOnLoad[uploadID];
+ if (img && img.parentNode) {
+ WCF.System.Event.fireEvent('com.woltlab.wcf.redactor2', 'replaceAttachment_' + this._editorId, {
+ attachmentId: attachmentData.attachmentID,
+ img: img,
+ src: (attachmentData.thumbnailURL) ? attachmentData.thumbnailURL : attachmentData.url
+ });
+ }
+ }
+
+ this._replaceOnLoad[uploadID] = null;
+ }
}
else {
// upload icon
this._autoInsert.splice(this._autoInsert.indexOf(uploadID), 1);
if (!$li.hasClass('uploadFailed')) {
- WCF.System.Event.fireEvent('com.woltlab.wcf.attachment', 'autoInsert_' + this._editorId, {
- attachment: '[attach=' + data.returnValues.attachments[$internalFileID].attachmentID + '][/attach]',
- uploadID: uploadID
- });
+ var btn = $li.find('.jsButtonAttachmentInsertThumbnail');
+ if (!btn.length) btn = $li.find('.jsButtonAttachmentInsertFull');
+
+ btn.trigger('click');
}
}
}
* Provides a specialized tab menu used for message options, integrates better into the editor.
*/
$.widget('wcf.messageTabMenu', {
- /**
- * pointer span
- * @var jQuery
- */
- _span: null,
-
/**
* list of existing tabs and their containers
* @var array<object>
return;
}
- // pointer span
- this._span = $('<span />').appendTo($nav);
-
var $preselect = this.element.data('preselect');
// check for tabs containing '.innerError' and select the first matching one instead
});
}
- this._span.css({
- transform: 'translateX(' + $target.tab[0].offsetLeft + 'px)',
- width: $target.tab[0].clientWidth + 'px'
- });
-
$(window).trigger('resize');
},
// show cursor to indicate editing capability excluding smilies
cursor: pointer;
}
+
+ /* prevent flicker from pasted images */
+ &[src^="data:image"] {
+ display: none !important;
+ }
}
// TODO: this is somewhat out of sync