Merge branch '2.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / 3rdParty / redactor / plugins / wupload.js
1 if (!RedactorPlugins) var RedactorPlugins = {};
2
3 /**
4 * Provides file uploads for Redactor.
5 *
6 * @author Alexander Ebert
7 * @copyright 2001-2014 WoltLab GmbH
8 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
9 */
10 RedactorPlugins.wupload = {
11 /**
12 * attachments container object
13 * @var jQuery
14 */
15 _attachmentsContainer: null,
16
17 /**
18 * Initializes the RedactorPlugins.wupload plugin.
19 */
20 init: function() {
21 var self = this;
22 this.buttonReplace('upload', 'upload', 'Upload', function() { self._attachmentsContainer.toggle(); });
23 this.buttonAwesome('upload', 'fa-upload');
24
25 this._initAttachments();
26 },
27
28 /**
29 * Initializes the attachments user interface.
30 */
31 _initAttachments: function() {
32 this._attachmentsContainer = $('<div class="redactorAttachmentContainer" />').hide().appendTo(this.$box);
33 var $attachmentList = $('<ul class="formAttachmentList clearfix" />').hide().appendTo(this._attachmentsContainer);
34 $('<dl class="wide"><dt></dt><dd><div data-max-size="{@$attachmentHandler->getMaxSize()}"></div><small>' + WCF.String.unescapeHTML(WCF.Language.get('wcf.attachment.upload.limits')) + '</small></dd></dl>').appendTo(this._attachmentsContainer);
35
36 var $options = this.getOption('wattachment');
37 if ($options.attachments.length) {
38 for (var $i = 0; $i < $options.attachments.length; $i++) {
39 var $attachment = $options.attachments[$i];
40 var $listItem = $('<li class="box48" />');
41 if ($attachment.tinyThumbnailUrl) {
42 $('<img src="' + $attachment.tinyThumbnailUrl + '" alt="" class="attachmentTinyThumbnail" />').appendTo($listItem);
43 }
44 else {
45 $('<span class="icon icon48 icon-paper-clip" />').appendTo($listItem);
46 }
47
48 var $div = $('<div />').appendTo($listItem);
49 $('<div><p><a href="' + $attachment.url + '"' + ($attachment.isImage ? ' title="' + $attachment.filename + '" class="jsImageViewer"' : '') + '>' + $attachment.filename + '</a></p></div>').appendTo($div);
50 var $list = $('<ul />').appendTo($div);
51 $('<li><span class="icon icon16 icon-remove pointer jsTooltip jsDeleteButton " title="' + WCF.Language.get('wcf.global.button.delete') + '" data-object-id="' + $attachment.attachmentID + '" data-confirm-message="' + WCF.Language.get('wcf.attachment.delete.sure') + '"></span></li>').appendTo($list);
52 $('<li><span class="icon icon16 icon-paste pointer jsTooltip jsButtonInsertAttachment" title="' + WCF.Language.get('wcf.attachment.insert') + '" data-object-id="' + $attachment.attachmentID + '"></span></li>').appendTo($list);
53
54 $listItem.appendTo($attachmentList);
55
56 this._attachmentsContainer.show();
57 $attachmentList.show();
58 }
59 }
60
61 new WCF.Attachment.Upload(this._attachmentsContainer.find('> dl > dd > div'), this._attachmentsContainer.children('ul'), $options.objectType, $options.objectID, $options.tmpHash, $options.parentObjectID, $options.maxCount, this.$source.wcfIdentify());
62 new WCF.Action.Delete('wcf\\data\\attachment\\AttachmentAction', '.formAttachmentList > li');
63 }
64 };