(function (window, undefined) { "use strict";WCF.ACL={},WCF.ACL.List=Class.extend({_categoryName:"",_container:null,_containerElements:{},_objectID:0,_objectTypeID:null,_options:{},_proxy:null,_search:null,_values:{group:{},user:{}},init:function(e,t,n,i,a,s,r){this._objectID=i||0,this._objectTypeID=t,this._categoryName=n,void 0===a&&(a=!0),this._values={group:{},user:{}},this._aclValuesFieldName=r||"aclValues",this._proxy=new WCF.Action.Proxy({showLoadingOverlay:!1,success:$.proxy(this._success,this)}),this._container=$(e).hide().addClass("aclContainer");var c=this._container.children("dd"),l=$('<ul class="aclList containerList" />').appendTo(c),o=$('<input type="text" class="long" placeholder="'+WCF.Language.get("wcf.acl.search."+(a?"":"user.")+"description")+'" />').appendTo(c),h=$('<ul class="aclPermissionList containerList" />').hide().appendTo(c);elData(h[0],"grant",WCF.Language.get("wcf.acl.option.grant")),elData(h[0],"deny",WCF.Language.get("wcf.acl.option.deny")),this._containerElements={aclList:l,denyAll:null,grantAll:null,permissionList:h,searchInput:o},this._search=new WCF.Search.User(o,$.proxy(this.addObject,this),a);var p=this._container.parents("form:eq(0)");p.submit($.proxy(this.submit,this));var d=p.find("input[type=reset]:eq(0)");d.length&&d.click($.proxy(this._reset,this)),s?this._success(s):this._loadACL()},_reset:function(){this._values={group:{},user:{}},this._containerElements.aclList.empty(),this._containerElements.searchInput.val(""),this._containerElements.permissionList.hide().find("input[type=checkbox]").prop("checked",!1)},_loadACL:function(){this._proxy.setOption("data",{actionName:"loadAll",className:"wcf\\data\\acl\\option\\ACLOptionAction",parameters:{categoryName:this._categoryName,objectID:this._objectID,objectTypeID:this._objectTypeID}}),this._proxy.sendRequest()},addObject:function(e){var t=this._createListItem(e.objectID,e.label,e.type);this._savePermissions(),this._containerElements.aclList.children("li").removeClass("active"),t.addClass("active"),this._search.addExcludedSearchValue(e.label),this._containerElements.permissionList.find("input[type=checkbox]").prop("checked",!1),this._containerElements.searchInput.val(""),this._containerElements.permissionList.show(),WCF.DOMNodeInsertedHandler.execute()},_createListItem:function(e,t,n){var i=$('<li><span class="icon icon16 fa-user'+("group"===n?"s":"")+'" /> <span class="aclLabel">'+t+"</span></li>").appendTo(this._containerElements.aclList);return i.data("objectID",e).data("type",n).data("label",t).click($.proxy(this._click,this)),$('<span class="icon icon16 fa-times jsTooltip pointer" title="'+WCF.Language.get("wcf.global.button.delete")+'" />').click($.proxy(this._removeItem,this)).appendTo(i),i},_removeItem:function(e){var t=$(e.currentTarget).parent(),n=t.data("type"),i=t.data("objectID");this._search.removeExcludedSearchValue(t.data("label")),t.remove(),this._values[n][i]&&delete this._values[n][i],this._selectFirstEntry()},_selectFirstEntry:function(){var e=this._containerElements.aclList.children("li:eq(0)");e.length?this._select(e,!1):this._reset()},_success:function(e,t,n){if($.getLength(e.returnValues.options)){var i=0,a={};for(var s in e.returnValues.options){var r=e.returnValues.options[s],c=$("<li><span>"+r.label+"</span></li>").data("optionID",s).data("optionName",r.optionName),l=$('<input type="checkbox" id="grant'+s+'" />').appendTo(c).wrap('<label for="grant'+s+'" class="jsTooltip" title="'+WCF.Language.get("wcf.acl.option.grant")+'" />'),o=$('<input type="checkbox" id="deny'+s+'" />').appendTo(c).wrap('<label for="deny'+s+'" class="jsTooltip" title="'+WCF.Language.get("wcf.acl.option.deny")+'" />');l.data("type","grant").data("optionID",s).change($.proxy(this._change,this)),o.data("type","deny").data("optionID",s).change($.proxy(this._change,this)),a[r.categoryName]||(a[r.categoryName]=[]),""===r.categoryName?c.appendTo(this._containerElements.permissionList):a[r.categoryName].push(c),i++}if(1<i&&(c=$('<li class="aclFullAccess"><span>'+WCF.Language.get("wcf.acl.option.fullAccess")+"</span></li>").prependTo(this._containerElements.permissionList),this._containerElements.grantAll=$('<input type="checkbox" id="grantAll_'+this._container.attr("id")+'" />').appendTo(c).wrap('<label class="jsTooltip" title="'+WCF.Language.get("wcf.acl.option.grant")+'" />'),this._containerElements.denyAll=$('<input type="checkbox" id="denyAll_'+this._container.attr("id")+'" />').appendTo(c).wrap('<label class="jsTooltip" title="'+WCF.Language.get("wcf.acl.option.deny")+'" />'),this._containerElements.grantAll.data("type","grant").change($.proxy(this._changeAll,this)),this._containerElements.denyAll.data("type","deny").change($.proxy(this._changeAll,this))),$.getLength(a))for(var h in a){var p=a[h];e.returnValues.categories[h]&&$('<li class="aclCategory">'+e.returnValues.categories[h]+"</li>").appendTo(this._containerElements.permissionList);for(var d=0,u=p.length;d<u;d++)p[d].appendTo(this._containerElements.permissionList)}this._parseData(e,"group"),this._parseData(e,"user"),this._container.show(),require(["WoltLabSuite/Core/Form/Builder/Field/Dependency/Manager"],function(e){e.checkDependencies()}),this._selectFirstEntry()}},_parseData:function(e,t){if($.getLength(e.returnValues[t].option)){for(var n in e.returnValues[t].label)this._createListItem(n,e.returnValues[t].label[n],t),this._search.addExcludedSearchValue(e.returnValues[t].label[n]);this._values[t]=e.returnValues[t].option,WCF.DOMNodeInsertedHandler.execute()}},_click:function(e){var t=$(e.currentTarget);t.hasClass("active")||this._select(t,!0)},_select:function(e,t){t&&this._savePermissions(),this._containerElements.aclList.children("li").removeClass("active"),e.addClass("active"),this._setupPermissions(e.data("type"),e.data("objectID"))},_change:function(e){var t=$(e.currentTarget),n=t.data("optionID"),i=t.data("type");t.is(":checked")?"deny"===i?($("#grant"+n).prop("checked",!1),null!==this._containerElements.grantAll&&this._containerElements.grantAll.prop("checked",!1)):($("#deny"+n).prop("checked",!1),null!==this._containerElements.denyAll&&this._containerElements.denyAll.prop("checked",!1)):"deny"===i&&null!==this._containerElements.denyAll?this._containerElements.denyAll.prop("checked",!1):"grant"===i&&null!==this._containerElements.grantAll&&this._containerElements.grantAll.prop("checked",!1);var a=!0;this._containerElements.permissionList.find("input[type=checkbox]").each($.proxy(function(e,t){var n=$(t);if(n.data("type")===i&&n.attr("id")!==i+"All_"+this._container.attr("id")&&!n.is(":checked"))return a=!1},this)),"deny"==i?null!==this._containerElements.denyAll&&(a?this._containerElements.denyAll.prop("checked",!0):this._containerElements.denyAll.prop("checked",!1)):null!==this._containerElements.grantAll&&(a?this._containerElements.grantAll.prop("checked",!0):this._containerElements.grantAll.prop("checked",!1))},_changeAll:function(e){var t=$(e.currentTarget),n=t.data("type");t.is(":checked")?"deny"===n?(this._containerElements.grantAll.prop("checked",!1),this._containerElements.permissionList.find("input[type=checkbox]").each($.proxy(function(e,t){var n=$(t);"deny"===n.data("type")&&n.attr("id")!=="denyAll_"+this._container.attr("id")&&n.prop("checked",!0).trigger("change")},this))):(this._containerElements.denyAll.prop("checked",!1),this._containerElements.permissionList.find("input[type=checkbox]").each($.proxy(function(e,t){var n=$(t);"grant"===n.data("type")&&n.attr("id")!=="grantAll_"+this._container.attr("id")&&n.prop("checked",!0).trigger("change")},this))):"deny"===n?(this._containerElements.grantAll.prop("checked",!1),this._containerElements.permissionList.find("input[type=checkbox]").each($.proxy(function(e,t){var n=$(t);"deny"===n.data("type")&&n.attr("id")!=="denyAll_"+this._container.attr("id")&&n.prop("checked",!1).trigger("change")},this))):(this._containerElements.denyAll.prop("checked",!1),this._containerElements.permissionList.find("input[type=checkbox]").each($.proxy(function(e,t){var n=$(t);"grant"===n.data("type")&&n.attr("id")!=="grantAll_"+this._container.attr("id")&&n.prop("checked",!1).trigger("change")},this)))},_setupPermissions:function(e,t){if(this._containerElements.permissionList.find("input[type='checkbox']").prop("checked",!1),this._values[e]&&this._values[e][t])for(var n in this._values[e][t])1==this._values[e][t][n]?$("#grant"+n).prop("checked",!0).trigger("change"):$("#deny"+n).prop("checked",!0).trigger("change");this._containerElements.permissionList.show()},_savePermissions:function(){var s,r,e=this._containerElements.aclList.find("li.active");e.length&&(s=e.data("objectID"),r=e.data("type"),this._values[r][s]={},this._containerElements.permissionList.find("input[type='checkbox']").each(function(e,t){var n,i,a=$(t);a.attr("id")!="grantAll_"+this._container.attr("id")&&a.attr("id")!="denyAll_"+this._container.attr("id")&&(n="deny"===a.data("type")?0:1,i=a.data("optionID"),a.is(":checked")?(this._values[r][s][i]=n,a.prop("checked",!1)):this._values[r]&&this._values[r][s]&&this._values[r][s][i]&&this._values[r][s][i]==n&&delete this._values[r][s][i])}.bind(this)))},submit:function(e){this._savePermissions(),this._save("group"),this._save("user")},_save:function(e){if($.getLength(this._values[e])){var t=this._container.parents("form:eq(0)");for(var n in this._values[e]){var i=this._values[e][n];for(var a in i)$('<input type="hidden" name="'+this._aclValuesFieldName+"["+e+"]["+n+"]["+a+']" value="'+i[a]+'" />').appendTo(t)}}},getData:function(){return this._savePermissions(),this._values}}); })(this);
// WCF.Attachment.js
-(function (window, undefined) { "use strict";WCF.Attachment={},WCF.Attachment.Upload=WCF.Upload.extend({_autoInsert:[],_insertAllButton:null,_objectType:"",_objectID:0,_tmpHash:"",_parentObjectID:0,_editorId:"",_replaceOnLoad:{},_options:{},init:function(t,e,i,a,n,s,r,l,o){var d,c;this._super(t,e,"wcf\\data\\attachment\\AttachmentAction",{multiple:!0,maxUploads:r}),this._autoInsert=[],this._objectType=i,this._objectID=parseInt(a),this._tmpHash=n,this._parentObjectID=parseInt(s),this._editorId=l,this._options=$.extend(!0,this._options,o||{}),this._buttonSelector.children("p.button").click($.proxy(this._validateLimit,this)),this._fileListSelector.find(".jsButtonInsertAttachment").click($.proxy(this._insert,this)),this._fileListSelector.find(".jsButtonAttachmentInsertThumbnail").click($.proxy(this._insert,this)),this._fileListSelector.find(".jsButtonAttachmentInsertFull").click($.proxy(this._insert,this)),WCF.System.Event.addListener("com.woltlab.wcf.action.delete","attachment",this._onDelete.bind(this)),this._makeSortable(),this._insertAllButton=$('<p class="button jsButtonAttachmentInsertAll">'+WCF.Language.get("wcf.attachment.insertAll")+"</p>").hide(),this._editorId&&(this._insertAllButton.appendTo(this._buttonSelector),this._insertAllButton.click($.proxy(this._insertAll,this)),this._fileListSelector.children("li:not(.uploadFailed)").length&&this._insertAllButton.show(),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)),WCF.System.Event.addListener("com.woltlab.wcf.redactor2","autosaveMetaData_"+this._editorId,function(t){t.tmpHashes&&Array.isArray(t.tmpHashes)||(t.tmpHashes=[]);var e=t.tmpHashes.indexOf(n);0<this._fileListSelector.children("li:not(.uploadFailed)").length?-1===e&&t.tmpHashes.push(n):-1!==e&&t.tmpHashes.splice(e)}.bind(this)),d=WCF.System.Event.addListener("com.woltlab.wcf.redactor2","metacode_attach_"+this._editorId,function(t){var e,i,a,n,s,r=this._getImageAttachments(),l=t.attributes[0]||0;r.hasOwnProperty(l)&&(e=~~$("#"+this._editorId).data("redactor").opts.woltlab.attachmentThumbnailWidth,i=!0===(i=t.attributes[2])||"true"===i||~~i&&~~i<=e,(a=elCreate("img")).className="woltlabAttachment",a.src=r[l][i?"thumbnailUrl":"url"],elData(a,"attachment-id",l),"left"===(n=t.attributes[1]||"none")?a.classList.add("messageFloatObjectLeft"):"right"===n&&a.classList.add("messageFloatObjectRight"),(s=t.metacode).parentNode.insertBefore(a,s),elRemove(s),t.cancel=!0)}.bind(this)),c=WCF.System.Event.addListener("com.woltlab.wcf.redactor2","sync_"+this._tmpHash,this._sync.bind(this)),WCF.System.Event.addListener("com.woltlab.wcf.redactor2","destroy_"+this._editorId,function(){WCF.System.Event.removeAllListeners("com.woltlab.wcf.redactor2","submit_"+this._editorId),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.removeAllListeners("com.woltlab.wcf.redactor2","autosaveMetaData_"+this._editorId),WCF.System.Event.removeListener("com.woltlab.wcf.redactor2","metacode_attach_"+this._editorId,d),WCF.System.Event.removeListener("com.woltlab.wcf.redactor2","sync_"+this._tmpHash,c)}.bind(this)))},_editorUpload:function(e){var i=null;this._fileListSelector.closest(".messageTabMenu").messageTabMenu("showTab","attachments",!0);var t=function(t){null===i?this._autoInsert.push(t):this._replaceOnLoad[t]=i,e.uploadID=t}.bind(this);e.file?this._upload(void 0,e.file,void 0,t):(this._upload(void 0,void 0,e.blob,t),i=e.replace||null)},_getImageAttachments:function(){var a={};return this._fileListSelector.children("li").each(function(t,e){var i=$(e);i.data("isImage")&&(a[~~i.data("objectID")]={thumbnailUrl:i.find(".jsButtonAttachmentInsertThumbnail").data("url"),url:i.find(".jsButtonAttachmentInsertFull").data("url")})}),a},_submitInline:function(t){var e;this._tmpHash&&(t.tmpHash=this._tmpHash,e={},WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","getMetaData_"+this._editorId,e),e.tmpHashes&&Array.isArray(e.tmpHashes)&&0<e.tmpHashes.length&&(t.tmpHash+=","+e.tmpHashes.join(",")))},_reset:function(){this._fileListSelector.hide().empty(),this._insertAllButton.hide(),this._validateLimit()},_validateLimit:function(){var t=this._buttonSelector.next("small.innerError"),e=this._options.maxUploads-this._fileListSelector.children("li:not(.uploadFailed)").length,i=this._fileUpload?this._fileUpload.prop("files").length:0;if(e<=0||e<i){var a=e<=0?WCF.Language.get("wcf.attachment.upload.error.reachedLimit"):WCF.Language.get("wcf.attachment.upload.error.reachedRemainingLimit").replace(/#remaining#/,e);return t.length||(t=$('<small class="innerError" />').insertAfter(this._buttonSelector)),t.html(a),!1}return t.remove(),!0},_removeLimitError:function(t){var e=this._fileListSelector.children("li");e.filter(":not(.uploadFailed)").length||this._insertAllButton.hide(),e.length||this._fileListSelector.hide(),this._editorId&&t.button&&WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","deleteAttachment_"+this._editorId,{attachmentId:t.button.data("objectID")})},_upload:function(s,r,l,o){var m=this._super.bind(this);require(["WoltLabSuite/Core/FileUtil","WoltLabSuite/Core/Image/ImageUtil","WoltLabSuite/Core/Image/Resizer","WoltLabSuite/Core/Ajax/Status"],function(t,d,e,i){i.show();var a=[];r?a.push(r):l?a.push(t.blobToFile(l,"pasted-from-clipboard")):a=this._fileUpload.prop("files");var c,h,n=Promise.resolve(a);this._options.autoScale&&this._options.autoScale.enable&&(c=this._buttonSelector.data("maxSize"),h=new e,n=Array.prototype.reduce.call(a,function(t,o){return t.then(function(e){if(-1===["image/png","image/jpeg"].indexOf(o.type))return e.push(o),e;var l=new Promise(function(t,e){setTimeout(function(){t(o)},1e4)}),t=h.loadFile(o).then(function(t){var e,i,a=t.exif,n=this._options.autoScale.maxWidth,s=this._options.autoScale.maxHeight,r=this._options.autoScale.quality;return 2<=window.devicePixelRatio&&(e=window.screen.width*window.devicePixelRatio,i=window.screen.height*window.devicePixelRatio,e-10<t.image.width&&t.image.width<10+e&&i-10<t.image.height&&(n=Math.min(n,window.screen.width))),h.resize(t.image,n,s,r,o.size>c,l).then(function(t){if(void 0===t)return o;var e=this._options.autoScale.fileType;return"keep"!==this._options.autoScale.fileType&&!d.containsTransparentPixels(t)||(e=o.type),h.saveFile({exif:a,image:t},o.name,e,r)}.bind(this)).then(function(t){return t.size>o.size?(console.debug('[WCF.Attachment] File size of "'+o.name+'" increased, uploading untouched image.'),o):t})}.bind(this)).catch(function(t){return console.debug('[WCF.Attachment] Failed to resize image "'+o.name+'":',t),o});return Promise.race([l,t]).then(function(t){return e.push(t),e})}.bind(this))}.bind(this),Promise.resolve([]))),n.then(function(t){var e=void 0;return this._validateLimit()&&(e=m(s,void 0,void 0,t)),this._fileUpload&&(this._removeButton(),this._createButton()),"function"==typeof o&&o(e),e}.bind(this)).catch(function(t){console.debug("[WCF.Attachment] Failed to upload attachments:",t)}).finally(i.hide)}.bind(this),function(t){console.debug("[WCF.Attachment] Failed to load modules:",t)})},_createUploadMatrix:function(t){return this._fileListSelector.children("li.uploadFailed").remove(),this._super(t)},_getParameters:function(){return{objectType:this._objectType,objectID:this._objectID,tmpHash:this._tmpHash,parentObjectID:this._parentObjectID}},_initFile:function(t){var e=$('<li class="box64 formAttachmentListItem"><span class="icon icon64 fa-spinner" /><div><div><p>'+t.name+'</p><small><progress max="100"></progress></small></div><ul></ul></div></li>').data("filename",t.name);return this._fileListSelector.append(e),this._fileListSelector.show(),this._buttonSelector.data("maxSize")<t.size&&(e.find("progress").remove(),e.children(".fa-spinner").removeClass("fa-spinner").addClass("fa-ban"),e.find("div > div").append($('<small class="innerError">'+WCF.Language.get("wcf.attachment.upload.error.tooLarge")+"</small>")),e.addClass("uploadFailed")),e},_useThumbnail:function(){return!0},_success:function(t,e){var i,a,n,s,r,l,o,d,c,h,m;for(var u in this._uploadMatrix[t]){this._uploadMatrix[t].hasOwnProperty(u)&&((a=this._uploadMatrix[t][u]).find("progress").remove(),n=a.data("filename"),s=a.data("internalFileID"),e.returnValues&&e.returnValues.attachments[s]?(i=e.returnValues.attachments[s],elData(a[0],"object-id",i.attachmentID),i.tinyURL?(a.children(".fa-spinner").replaceWith($('<img src="'+i.tinyURL+'" alt="" class="attachmentTinyThumbnail" />')),a.data("height",i.height),a.data("width",i.width),elData(a[0],"is-image",i.isImage)):a.children(".fa-spinner").removeClass("fa-spinner").addClass("fa-"+i.iconName),(r=$('<a href=""></a>')).text(n).attr("href",i.url),r[0].target="_blank",0!=i.isImage&&r.addClass("jsImageViewer").attr("title",n),a.find("p").empty().append(r),a.find("small").append(i.formattedFilesize),l=a.find("ul").addClass("buttonGroup"),o=$('<li><span class="button small jsDeleteButton" data-object-id="'+i.attachmentID+'" data-confirm-message="'+WCF.Language.get("wcf.attachment.delete.sure")+'" data-event-name="attachment">'+WCF.Language.get("wcf.global.button.delete")+"</span></li>"),l.append(o),a.data("objectID",i.attachmentID),this._editorId&&(i.tinyURL?(i.thumbnailURL&&$('<li><span class="button small jsButtonAttachmentInsertThumbnail" data-object-id="'+i.attachmentID+'" data-url="'+WCF.String.escapeHTML(i.thumbnailURL)+'">'+WCF.Language.get("wcf.attachment.insertThumbnail")+"</span></li>").appendTo(l),$('<li><span class="button small jsButtonAttachmentInsertFull" data-object-id="'+i.attachmentID+'" data-url="'+WCF.String.escapeHTML(i.url)+'">'+WCF.Language.get("wcf.attachment.insertFull")+"</span></li>").appendTo(l)):$('<li><span class="button small jsButtonAttachmentInsertPlain" data-object-id="'+i.attachmentID+'">'+WCF.Language.get("wcf.attachment.insert")+"</span></li>").appendTo(l)),this._triggerSync("new",{html:a[0].outerHTML}),this._registerEditorButtons(a[0]),this._replaceOnLoad.hasOwnProperty(t)&&(a.hasClass("uploadFailed")||(d=this._replaceOnLoad[t])&&d.parentNode&&WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","replaceAttachment_"+this._editorId,{attachmentId:i.attachmentID,img:d,src:i.thumbnailURL?i.thumbnailURL:i.url}),this._replaceOnLoad[t]=null)):(a.children(".fa-spinner").removeClass("fa-spinner").addClass("fa-ban"),h="",e.returnValues&&e.returnValues.errors[s]?"uploadFailed"===(h=(c=e.returnValues.errors[s]).errorType)&&c.additionalData.phpLimitExceeded&&(h="uploadPhpLimit"):h="uploadFailed",a.find("div > div").append($('<small class="innerError">'+WCF.Language.get("wcf.attachment.upload.error."+h)+"</small>")),a.addClass("uploadFailed")),WCF.inArray(t,this._autoInsert)&&(this._autoInsert.splice(this._autoInsert.indexOf(t),1),a.hasClass("uploadFailed")||((m=a.find(".jsButtonAttachmentInsertThumbnail")).length||(m=a.find(".jsButtonAttachmentInsertFull")),m.trigger("click"))))}this._rebuildInterface()},_rebuildInterface:function(){this._makeSortable(),this._fileListSelector.children("li:not(.uploadFailed)").length?this._insertAllButton.show():this._insertAllButton.hide(),WCF.DOMNodeInsertedHandler.execute()},_registerEditorButtons:function(t){this._editorId&&elBySelAll(".jsButtonAttachmentInsertThumbnail, .jsButtonAttachmentInsertFull, .jsButtonAttachmentInsertPlain",t,function(t){t.addEventListener("click",this._insert.bind(this))}.bind(this))},_insert:function(t){WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","insertAttachment_"+this._editorId,{attachmentId:elData(t.currentTarget,"object-id"),url:elData(t.currentTarget,"url")})},_insertAll:function(){for(var t,e,i=0,a=this._fileListSelector[0].childNodes.length;i<a;i++)"LI"!==(t=this._fileListSelector[0].childNodes[i]).nodeName||t.classList.contains("uploadFailed")||(null===(e=elBySel(".jsButtonAttachmentInsertThumbnail, .jsButtonAttachmentInsertPlain",t))&&(e=elBySel(".jsButtonAttachmentInsertFull, .jsButtonAttachmentInsertPlain",t)),window.jQuery(e).trigger("click"))},_error:function(a){this._fileListSelector.find("li").each(function(t,e){var i=$(e);i.children(".fa-spinner").length&&(i.addClass("uploadFailed").children(".fa-spinner").removeClass("fa-spinner").addClass("fa-ban"),i.find("div > div").append($('<small class="innerError">'+(a.responseJSON&&a.responseJSON.message?a.responseJSON.message:WCF.Language.get("wcf.attachment.upload.error.uploadFailed"))+"</small>")))})},_makeSortable:function(){var t=this._fileListSelector.children("li:not(.uploadFailed)");t.length&&(t.addClass("sortableAttachment").children("img").addClass("sortableNode"),this._fileListSelector.hasClass("sortableList")||(this._fileListSelector.addClass("sortableList"),require(["Environment"],function(t){"desktop"===t.platform()&&new WCF.Sortable.List(this._fileListSelector.parent().wcfIdentify(),"",0,{axis:!1,items:"li.sortableAttachment",toleranceElement:null,start:function(t,e){e.placeholder[0].style.setProperty("height",e.helper[0].offsetHeight+"px","")},update:function(){var i=[];this._fileListSelector.children("li:not(.uploadFailed)").each(function(t,e){i.push($(e).data("objectID"))}),i.length&&new WCF.Action.Proxy({autoSend:!0,data:{actionName:"updatePosition",className:"wcf\\data\\attachment\\AttachmentAction",parameters:{attachmentIDs:i,objectID:this._objectID,objectType:this._objectType,tmpHash:this._tmpHash}}})}.bind(this)},!0)}.bind(this))))},_onDelete:function(t){var e=elData(t.button[0],"object-id"),i=elBySel('.formAttachmentListItem[data-object-id="'+e+'"]',this._fileListSelector[0]);null!==i&&elRemove(i),this._removeLimitError(t)},_sync:function(t){if(t.source!==this)switch(t.type){case"new":this._syncNew(t.data);break;default:throw new Error("Unexpected type '"+t.type+"'")}},_syncNew:function(a){require(["Dom/Util"],function(t){var e=t.createFragmentFromHtml(a.html),i=elBySel("li",e);i.id="",this._registerEditorButtons(i),this._fileListSelector[0].appendChild(i),elShow(this._fileListSelector[0]),this._rebuildInterface()}.bind(this))},_triggerSync:function(t,e){WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","sync_"+this._tmpHash,{source:this,type:t,data:e})}}); })(this);
+(function (window, undefined) { "use strict";WCF.Attachment={},WCF.Attachment.Upload=WCF.Upload.extend({_autoInsert:[],_insertAllButton:null,_objectType:"",_objectID:0,_tmpHash:"",_parentObjectID:0,_editorId:"",_replaceOnLoad:{},_options:{},init:function(t,e,i,a,n,s,r,l,o){var d,c;this._super(t,e,"wcf\\data\\attachment\\AttachmentAction",{multiple:!0,maxUploads:r}),this._autoInsert=[],this._objectType=i,this._objectID=parseInt(a),this._tmpHash=n,this._parentObjectID=parseInt(s),this._editorId=l,this._options=$.extend(!0,this._options,o||{}),this._buttonSelector.children("p.button").click($.proxy(this._validateLimit,this)),this._fileListSelector.find(".jsButtonInsertAttachment").click($.proxy(this._insert,this)),this._fileListSelector.find(".jsButtonAttachmentInsertThumbnail").click($.proxy(this._insert,this)),this._fileListSelector.find(".jsButtonAttachmentInsertFull").click($.proxy(this._insert,this)),WCF.System.Event.addListener("com.woltlab.wcf.action.delete","attachment",this._onDelete.bind(this)),this._makeSortable(),this._insertAllButton=$('<p class="button jsButtonAttachmentInsertAll">'+WCF.Language.get("wcf.attachment.insertAll")+"</p>").hide(),this._editorId&&(this._insertAllButton.appendTo(this._buttonSelector),this._insertAllButton.click($.proxy(this._insertAll,this)),this._fileListSelector.children("li:not(.uploadFailed)").length&&this._insertAllButton.show(),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)),WCF.System.Event.addListener("com.woltlab.wcf.redactor2","autosaveMetaData_"+this._editorId,function(t){t.tmpHashes&&Array.isArray(t.tmpHashes)||(t.tmpHashes=[]);var e=t.tmpHashes.indexOf(n);0<this._fileListSelector.children("li:not(.uploadFailed)").length?-1===e&&t.tmpHashes.push(n):-1!==e&&t.tmpHashes.splice(e)}.bind(this)),d=WCF.System.Event.addListener("com.woltlab.wcf.redactor2","metacode_attach_"+this._editorId,function(t){var e,i,a,n,s,r=this._getImageAttachments(),l=t.attributes[0]||0;r.hasOwnProperty(l)&&(e=~~$("#"+this._editorId).data("redactor").opts.woltlab.attachmentThumbnailWidth,i=!0===(i=t.attributes[2])||"true"===i||~~i&&~~i<=e,(a=elCreate("img")).className="woltlabAttachment",a.src=r[l][i?"thumbnailUrl":"url"],elData(a,"attachment-id",l),"left"===(n=t.attributes[1]||"none")?a.classList.add("messageFloatObjectLeft"):"right"===n&&a.classList.add("messageFloatObjectRight"),(s=t.metacode).parentNode.insertBefore(a,s),elRemove(s),t.cancel=!0)}.bind(this)),c=WCF.System.Event.addListener("com.woltlab.wcf.redactor2","sync_"+this._tmpHash,this._sync.bind(this)),WCF.System.Event.addListener("com.woltlab.wcf.redactor2","destroy_"+this._editorId,function(){WCF.System.Event.removeAllListeners("com.woltlab.wcf.redactor2","submit_"+this._editorId),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.removeAllListeners("com.woltlab.wcf.redactor2","autosaveMetaData_"+this._editorId),WCF.System.Event.removeListener("com.woltlab.wcf.redactor2","metacode_attach_"+this._editorId,d),WCF.System.Event.removeListener("com.woltlab.wcf.redactor2","sync_"+this._tmpHash,c)}.bind(this)))},_editorUpload:function(e){var i=null;this._fileListSelector.closest(".messageTabMenu").messageTabMenu("showTab","attachments",!0);var t=function(t){null===i?this._autoInsert.push(t):this._replaceOnLoad[t]=i,e.uploadID=t}.bind(this);e.file?this._upload(void 0,e.file,void 0,t):(this._upload(void 0,void 0,e.blob,t),i=e.replace||null)},_getImageAttachments:function(){var a={};return this._fileListSelector.children("li").each(function(t,e){var i=$(e);i.data("isImage")&&(a[~~i.data("objectID")]={thumbnailUrl:i.find(".jsButtonAttachmentInsertThumbnail").data("url"),url:i.find(".jsButtonAttachmentInsertFull").data("url")})}),a},_submitInline:function(t){var e;this._tmpHash&&(t.tmpHash=this._tmpHash,e={},WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","getMetaData_"+this._editorId,e),e.tmpHashes&&Array.isArray(e.tmpHashes)&&0<e.tmpHashes.length&&(t.tmpHash+=","+e.tmpHashes.join(",")))},_reset:function(){this._fileListSelector.hide().empty(),this._insertAllButton.hide(),this._validateLimit()},_validateLimit:function(){var t=this._buttonSelector.next("small.innerError"),e=this._options.maxUploads-this._fileListSelector.children("li:not(.uploadFailed)").length,i=this._fileUpload?this._fileUpload.prop("files").length:0;if(e<=0||e<i){var a=e<=0?WCF.Language.get("wcf.attachment.upload.error.reachedLimit"):WCF.Language.get("wcf.attachment.upload.error.reachedRemainingLimit").replace(/#remaining#/,e);return t.length||(t=$('<small class="innerError" />').insertAfter(this._buttonSelector)),t.html(a),!1}return t.remove(),!0},_removeLimitError:function(t){var e=this._fileListSelector.children("li");e.filter(":not(.uploadFailed)").length||this._insertAllButton.hide(),e.length||this._fileListSelector.hide(),this._editorId&&t.button&&WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","deleteAttachment_"+this._editorId,{attachmentId:t.button.data("objectID")})},_upload:function(s,r,l,o){var m=this._super.bind(this);require(["WoltLabSuite/Core/FileUtil","WoltLabSuite/Core/Image/ImageUtil","WoltLabSuite/Core/Image/Resizer","WoltLabSuite/Core/Ajax/Status"],function(t,d,e,i){i.show();var a=[];r?a.push(r):l?a.push(t.blobToFile(l,"pasted-from-clipboard")):a=this._fileUpload.prop("files");var c,h,n=Promise.resolve(a);this._options.autoScale&&this._options.autoScale.enable&&(c=this._buttonSelector.data("maxSize"),h=new e,n=Array.prototype.reduce.call(a,function(t,o){return t.then(function(e){if(-1===["image/png","image/jpeg"].indexOf(o.type))return e.push(o),e;var l=new Promise(function(t,e){setTimeout(function(){t(o)},1e4)}),t=h.loadFile(o).then(function(t){var e,i,a=t.exif,n=this._options.autoScale.maxWidth,s=this._options.autoScale.maxHeight,r=this._options.autoScale.quality;return 2<=window.devicePixelRatio&&(e=window.screen.width*window.devicePixelRatio,i=window.screen.height*window.devicePixelRatio,e-10<t.image.width&&t.image.width<10+e&&i-10<t.image.height&&(n=Math.min(n,window.screen.width))),h.resize(t.image,n,s,r,o.size>c,l).then(function(t){if(void 0===t)return o;var e=this._options.autoScale.fileType;return"keep"!==this._options.autoScale.fileType&&!d.containsTransparentPixels(t)||(e=o.type),h.saveFile({exif:a,image:t},o.name,e,r)}.bind(this)).then(function(t){return t.size>o.size?(console.debug('[WCF.Attachment] File size of "'+o.name+'" increased, uploading untouched image.'),o):t})}.bind(this)).catch(function(t){return console.debug('[WCF.Attachment] Failed to resize image "'+o.name+'":',t),o});return Promise.race([l,t]).then(function(t){return e.push(t),e})}.bind(this))}.bind(this),Promise.resolve([]))),n.then(function(t){var e=void 0;return this._validateLimit()&&(e=m(s,void 0,void 0,t)),this._fileUpload&&(this._removeButton(),this._createButton()),"function"==typeof o&&o(e),e}.bind(this)).catch(function(t){console.debug("[WCF.Attachment] Failed to upload attachments:",t)}).finally(i.hide)}.bind(this),function(t){console.debug("[WCF.Attachment] Failed to load modules:",t)})},_createUploadMatrix:function(t){return this._fileListSelector.children("li.uploadFailed").remove(),this._super(t)},_getParameters:function(){return{objectType:this._objectType,objectID:this._objectID,tmpHash:this._tmpHash,parentObjectID:this._parentObjectID}},_initFile:function(t){var e=$('<li class="box64 formAttachmentListItem"><span class="icon icon64 fa-spinner" /><div><div><p>'+WCF.String.escapeHTML(t.name)+'</p><small><progress max="100"></progress></small></div><ul></ul></div></li>').data("filename",t.name);return this._fileListSelector.append(e),this._fileListSelector.show(),this._buttonSelector.data("maxSize")<t.size&&(e.find("progress").remove(),e.children(".fa-spinner").removeClass("fa-spinner").addClass("fa-ban"),e.find("div > div").append($('<small class="innerError">'+WCF.Language.get("wcf.attachment.upload.error.tooLarge")+"</small>")),e.addClass("uploadFailed")),e},_useThumbnail:function(){return!0},_success:function(t,e){var i,a,n,s,r,l,o,d,c,h,m;for(var u in this._uploadMatrix[t]){this._uploadMatrix[t].hasOwnProperty(u)&&((a=this._uploadMatrix[t][u]).find("progress").remove(),n=a.data("filename"),s=a.data("internalFileID"),e.returnValues&&e.returnValues.attachments[s]?(i=e.returnValues.attachments[s],elData(a[0],"object-id",i.attachmentID),i.tinyURL?(a.children(".fa-spinner").replaceWith($('<img src="'+i.tinyURL+'" alt="" class="attachmentTinyThumbnail" />')),a.data("height",i.height),a.data("width",i.width),elData(a[0],"is-image",i.isImage)):a.children(".fa-spinner").removeClass("fa-spinner").addClass("fa-"+i.iconName),(r=$('<a href=""></a>')).text(n).attr("href",i.url),r[0].target="_blank",0!=i.isImage&&r.addClass("jsImageViewer").attr("title",n),a.find("p").empty().append(r),a.find("small").append(i.formattedFilesize),l=a.find("ul").addClass("buttonGroup"),o=$('<li><span class="button small jsDeleteButton" data-object-id="'+i.attachmentID+'" data-confirm-message="'+WCF.Language.get("wcf.attachment.delete.sure")+'" data-event-name="attachment">'+WCF.Language.get("wcf.global.button.delete")+"</span></li>"),l.append(o),a.data("objectID",i.attachmentID),this._editorId&&(i.tinyURL?(i.thumbnailURL&&$('<li><span class="button small jsButtonAttachmentInsertThumbnail" data-object-id="'+i.attachmentID+'" data-url="'+WCF.String.escapeHTML(i.thumbnailURL)+'">'+WCF.Language.get("wcf.attachment.insertThumbnail")+"</span></li>").appendTo(l),$('<li><span class="button small jsButtonAttachmentInsertFull" data-object-id="'+i.attachmentID+'" data-url="'+WCF.String.escapeHTML(i.url)+'">'+WCF.Language.get("wcf.attachment.insertFull")+"</span></li>").appendTo(l)):$('<li><span class="button small jsButtonAttachmentInsertPlain" data-object-id="'+i.attachmentID+'">'+WCF.Language.get("wcf.attachment.insert")+"</span></li>").appendTo(l)),this._triggerSync("new",{html:a[0].outerHTML}),this._registerEditorButtons(a[0]),this._replaceOnLoad.hasOwnProperty(t)&&(a.hasClass("uploadFailed")||(d=this._replaceOnLoad[t])&&d.parentNode&&WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","replaceAttachment_"+this._editorId,{attachmentId:i.attachmentID,img:d,src:i.thumbnailURL?i.thumbnailURL:i.url}),this._replaceOnLoad[t]=null)):(a.children(".fa-spinner").removeClass("fa-spinner").addClass("fa-ban"),h="",e.returnValues&&e.returnValues.errors[s]?"uploadFailed"===(h=(c=e.returnValues.errors[s]).errorType)&&c.additionalData.phpLimitExceeded&&(h="uploadPhpLimit"):h="uploadFailed",a.find("div > div").append($('<small class="innerError">'+WCF.Language.get("wcf.attachment.upload.error."+h)+"</small>")),a.addClass("uploadFailed")),WCF.inArray(t,this._autoInsert)&&(this._autoInsert.splice(this._autoInsert.indexOf(t),1),a.hasClass("uploadFailed")||((m=a.find(".jsButtonAttachmentInsertThumbnail")).length||(m=a.find(".jsButtonAttachmentInsertFull")),m.trigger("click"))))}this._rebuildInterface()},_rebuildInterface:function(){this._makeSortable(),this._fileListSelector.children("li:not(.uploadFailed)").length?this._insertAllButton.show():this._insertAllButton.hide(),WCF.DOMNodeInsertedHandler.execute()},_registerEditorButtons:function(t){this._editorId&&elBySelAll(".jsButtonAttachmentInsertThumbnail, .jsButtonAttachmentInsertFull, .jsButtonAttachmentInsertPlain",t,function(t){t.addEventListener("click",this._insert.bind(this))}.bind(this))},_insert:function(t){WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","insertAttachment_"+this._editorId,{attachmentId:elData(t.currentTarget,"object-id"),url:elData(t.currentTarget,"url")})},_insertAll:function(){for(var t,e,i=0,a=this._fileListSelector[0].childNodes.length;i<a;i++)"LI"!==(t=this._fileListSelector[0].childNodes[i]).nodeName||t.classList.contains("uploadFailed")||(null===(e=elBySel(".jsButtonAttachmentInsertThumbnail, .jsButtonAttachmentInsertPlain",t))&&(e=elBySel(".jsButtonAttachmentInsertFull, .jsButtonAttachmentInsertPlain",t)),window.jQuery(e).trigger("click"))},_error:function(a){this._fileListSelector.find("li").each(function(t,e){var i=$(e);i.children(".fa-spinner").length&&(i.addClass("uploadFailed").children(".fa-spinner").removeClass("fa-spinner").addClass("fa-ban"),i.find("div > div").append($('<small class="innerError">'+(a.responseJSON&&a.responseJSON.message?a.responseJSON.message:WCF.Language.get("wcf.attachment.upload.error.uploadFailed"))+"</small>")))})},_makeSortable:function(){var t=this._fileListSelector.children("li:not(.uploadFailed)");t.length&&(t.addClass("sortableAttachment").children("img").addClass("sortableNode"),this._fileListSelector.hasClass("sortableList")||(this._fileListSelector.addClass("sortableList"),require(["Environment"],function(t){"desktop"===t.platform()&&new WCF.Sortable.List(this._fileListSelector.parent().wcfIdentify(),"",0,{axis:!1,items:"li.sortableAttachment",toleranceElement:null,start:function(t,e){e.placeholder[0].style.setProperty("height",e.helper[0].offsetHeight+"px","")},update:function(){var i=[];this._fileListSelector.children("li:not(.uploadFailed)").each(function(t,e){i.push($(e).data("objectID"))}),i.length&&new WCF.Action.Proxy({autoSend:!0,data:{actionName:"updatePosition",className:"wcf\\data\\attachment\\AttachmentAction",parameters:{attachmentIDs:i,objectID:this._objectID,objectType:this._objectType,tmpHash:this._tmpHash}}})}.bind(this)},!0)}.bind(this))))},_onDelete:function(t){var e=elData(t.button[0],"object-id"),i=elBySel('.formAttachmentListItem[data-object-id="'+e+'"]',this._fileListSelector[0]);null!==i&&elRemove(i),this._removeLimitError(t)},_sync:function(t){if(t.source!==this)switch(t.type){case"new":this._syncNew(t.data);break;default:throw new Error("Unexpected type '"+t.type+"'")}},_syncNew:function(a){require(["Dom/Util"],function(t){var e=t.createFragmentFromHtml(a.html),i=elBySel("li",e);i.id="",this._registerEditorButtons(i),this._fileListSelector[0].appendChild(i),elShow(this._fileListSelector[0]),this._rebuildInterface()}.bind(this))},_triggerSync:function(t,e){WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","sync_"+this._tmpHash,{source:this,type:t,data:e})}}); })(this);
// WCF.ColorPicker.js
(function (window, undefined) { "use strict";WCF.ColorPicker=Class.extend({_bar:null,_barActive:!1,_barSelector:null,_callbackSubmit:null,_dialog:null,_didInit:!1,_elementID:"",_gradient:null,_gradientActive:!1,_gradientSelector:null,_hex:null,_hsv:{},_newColor:null,_oldColor:null,_rgba:{},_rgbaRegExp:null,init:function(t){this._callbackSubmit=null,this._elementID="",this._hsv={h:0,s:100,v:100},this._position={};var a=$(t);a.length?a.click($.proxy(this._open,this)):console.debug("[WCF.ColorPicker] Selector does not match any element, aborting.")},setCallbackSubmit:function(t){this._callbackSubmit=t},_open:function(t){this._didInit||(this._initColorPicker(),this._didInit=!0);var a=$(t.currentTarget);this._elementID=a.wcfIdentify(),this._parseColor(a);var i=this.hsvToRgb(this._hsv.h,this._hsv.s,this._hsv.v);this._oldColor.css({backgroundColor:"rgba("+i.r+", "+i.g+", "+i.b+", "+this._rgba.a.val()/100+")"}),this._dialog.wcfDialog({backdropCloseOnClick:!1,title:WCF.Language.get("wcf.style.colorPicker")}),window.setTimeout(function(){this._hex.focus()}.bind(this),200)},_parseColor:function(t){if(t.data("hsv")&&t.data("rgb")){var a=t.data("hsv");for(var i in a)this._hsv[i]=a[i];this._updateValues(t.data("rgb"),!0,!0),this._rgba.a.val(parseInt(t.data("alpha")))}else{t.data("color").match(/^rgb\((\d{1,3}), ?(\d{1,3}), ?(\d{1,3})\)$/)&&t.data("color","rgba("+RegExp.$1+", "+RegExp.$2+", "+RegExp.$3+", 1)"),null===this._rgbaRegExp&&(this._rgbaRegExp=new RegExp("^rgba\\((\\d{1,3}), ?(\\d{1,3}), ?(\\d{1,3}), ?(1|1\\.00?|0|0?\\.[0-9]{1,2})\\)$")),this._rgbaRegExp.exec(t.data("color"));var s=RegExp.$4;0===s.indexOf(".")&&(s="0"+s),s*=100,this._updateValues({r:RegExp.$1,g:RegExp.$2,b:RegExp.$3,a:Math.round(s)},!0,!0)}},_initColorPicker:function(){this._dialog=$('<div id="colorPickerContainer" />').hide().appendTo(document.body),this._gradient=$('<div id="colorPickerGradient" />').appendTo(this._dialog),this._gradientSelector=$('<span id="colorPickerGradientSelector"><span></span></span>').appendTo(this._gradient),this._bar=$('<div id="colorPickerBar" />').appendTo(this._dialog),this._barSelector=$('<span id="colorPickerBarSelector" />').appendTo(this._bar),this._gradient.mousedown($.proxy(this._mouseDownGradient,this)),this._bar.mousedown($.proxy(this._mouseDownBar,this));var a=this;$(document).mouseup(function(t){a._barActive?(a._barActive=!1,a._mouseBar(t)):a._gradientActive&&(a._gradientActive=!1,a._mouseGradient(t))}).mousemove(function(t){a._barActive?a._mouseBar(t):a._gradientActive&&a._mouseGradient(t)}),this._initColorPickerForm()},_initColorPickerForm:function(){var t=$('<div id="colorPickerForm" />').appendTo(this._dialog);$("<small>"+WCF.Language.get("wcf.style.colorPicker.new")+"</small>").appendTo(t);var a=$('<ul class="colors" />').appendTo(t);this._newColor=$('<li class="new"><span /></li>').appendTo(a).children("span"),this._oldColor=$('<li class="old"><span /></li>').appendTo(a).children("span"),$("<small>"+WCF.Language.get("wcf.style.colorPicker.current")+"</small>").appendTo(t);var i=$('<ul class="rgba" />').appendTo(t);this._createInputElement("r","R",0,255).appendTo(i),this._createInputElement("g","G",0,255).appendTo(i),this._createInputElement("b","B",0,255).appendTo(i),this._createInputElement("a","a",0,100).appendTo(i);var s=$('<ul class="hex"><li><label><span>#</span></label></li></ul>').appendTo(t);this._hex=$('<input type="text" maxlength="6" />').appendTo(s.find("label")),this._rgba.r.blur($.proxy(this._blurRgba,this)).keyup($.proxy(this._keyUpRGBA,this)),this._rgba.g.blur($.proxy(this._blurRgba,this)).keyup($.proxy(this._keyUpRGBA,this)),this._rgba.b.blur($.proxy(this._blurRgba,this)).keyup($.proxy(this._keyUpRGBA,this)),this._rgba.a.blur($.proxy(this._blurRgba,this)).keyup($.proxy(this._keyUpRGBA,this)),this._hex.blur($.proxy(this._blurHex,this)).keyup($.proxy(this._keyUpHex,this));var e=$('<div class="formSubmit" />').appendTo(this._dialog);$('<button class="buttonPrimary">'+WCF.Language.get("wcf.style.colorPicker.button.apply")+"</button>").appendTo(e).click($.proxy(this._submit,this));var r=this;this._hex.on("paste",function(){r._hex.attr("maxlength","7"),setTimeout(function(){var t=r._hex.val();"#"==t.substring(0,1)&&(t=t.substr(1)),6<t.length&&(t=t.substring(0,6)),r._hex.attr("maxlength","6").val(t)},50)}),t.find("input").focus(function(){this.select()})},_keyUpRGBA:function(t){13==t.which&&(this._blurRgba(),this._submit())},_keyUpHex:function(t){13==t.which&&(this._blurHex(),this._submit())},_submit:function(){var t=this.hsvToRgb(this._hsv.h,this._hsv.s,this._hsv.v),a={};for(var i in this._hsv)a[i]=this._hsv[i];var s=$("#"+this._elementID);s.data("hsv",a).css({backgroundColor:"rgba("+t.r+", "+t.g+", "+t.b+", "+this._rgba.a.val()/100+")"}).data("alpha",parseInt(this._rgba.a.val())),s.data("rgb",{r:this._rgba.r.val(),g:this._rgba.g.val(),b:this._rgba.b.val()}),$("#"+s.data("store")).val("rgba("+this._rgba.r.val()+", "+this._rgba.g.val()+", "+this._rgba.b.val()+", "+this._rgba.a.val()/100+")").trigger("change"),this._dialog.wcfDialog("close"),"function"==typeof this._callbackSubmit&&this._callbackSubmit({r:this._rgba.r.val(),g:this._rgba.g.val(),b:this._rgba.b.val(),a:this._rgba.a.val()/100})},_createInputElement:function(t,a,i,s){var e=$('<li class="'+t+'" />'),r=$("<label />").appendTo(e);return $("<span>"+a+"</span>").appendTo(r),this._rgba[t]=$('<input type="number" value="0" min="'+i+'" max="'+s+'" step="1" />').appendTo(r),e},_mouseDownGradient:function(t){this._gradientActive=!0,this._mouseGradient(t)},_mouseGradient:function(t){var a=this._gradient.getOffsets("offset"),i=Math.max(Math.min(t.pageX-a.left,255),0),s=Math.max(Math.min(t.pageY-a.top,255),0);this._hsv.s=100*Math.max(0,Math.min(1,i/255)),this._hsv.v=100*Math.max(0,Math.min(1,(255-s)/255)),this._updateValues(null)},_mouseDownBar:function(t){this._barActive=!0,this._mouseBar(t)},_mouseBar:function(t){var a=this._bar.getOffsets("offset"),i=Math.max(Math.min(t.pageY-a.top,255),0);this._barSelector.css({top:i+"px"}),this._hsv.h=Math.max(0,Math.min(359,Math.round((255-i)/255*360))),this._updateValues(null)},_blurRgba:function(){for(var t in this._rgba){var a=parseInt(this._rgba[t].val())||0;"a"===t?this._rgba[t].val(Math.max(0,Math.min(100,a))):this._rgba[t].val(Math.max(0,Math.min(255,a)))}this._updateValues({r:this._rgba.r.val(),g:this._rgba.g.val(),b:this._rgba.b.val()},!0,!0)},_blurHex:function(){var t=this.hexToRgb(this._hex.val());t!==Number.NaN&&this._updateValues(t,!0,!0)},_updateValues:function(t,a,i){for(var s in a=!0===a,i=!0===i,null===t&&(t=this.hsvToRgb(this._hsv.h,this._hsv.s,this._hsv.v),0==this._rgba.a.val()&&(t.a=100)),void 0===t.a&&(t.a=this._rgba.a.val()),t)this._rgba[s].val(t[s]);var e;this._hex.val(this.rgbToHex(t.r,t.g,t.b)),(a||i)&&(e=this.rgbToHsv(t.r,t.g,t.b),a&&(this._hsv.h=e.h),i&&(this._hsv.s=e.s,this._hsv.v=e.v));var r=Math.max(0,Math.min(255,255-this._hsv.h/360*255));this._barSelector.css({top:r+"px"});var o=Math.max(0,Math.min(255,this._hsv.s/100*255)),r=Math.max(0,Math.min(255,255-this._hsv.v/100*255));this._gradientSelector.css({left:o-6+"px",top:r-6+"px"}),this._newColor.css({backgroundColor:"rgba("+t.r+", "+t.g+", "+t.b+", "+t.a/100+")"});var h=this.hsvToRgb(this._hsv.h,100,100);this._gradient.css({backgroundColor:"rgb("+h.r+", "+h.g+", "+h.b+")"})},hsvToRgb:function(t,a,i){return window.__wcf_bc_colorUtil.hsvToRgb(t,a,i)},rgbToHsv:function(t,a,i){return window.__wcf_bc_colorUtil.rgbToHsv(t,a,i)},hexToRgb:function(t){return window.__wcf_bc_colorUtil.hexToRgb(t)},rgbToHex:function(t,a,i){return window.__wcf_bc_colorUtil.rgbToHex(t,a,i)}}),void 0===window.__wcf_bc_colorUtil&&require(["ColorUtil"],function(t){}),"function"==typeof window.__wcf_bc_colorPickerInit&&window.__wcf_bc_colorPickerInit(); })(this);
(function (window, undefined) { "use strict";WCF.ACL={},WCF.ACL.List=Class.extend({_categoryName:"",_container:{},_containerElements:{},_objectID:0,_objectTypeID:{},_options:{},_proxy:{},_search:{},_values:{},init:function(){},_reset:function(){},_loadACL:function(){},addObject:function(){},_createListItem:function(){},_removeItem:function(){},_selectFirstEntry:function(){},_success:function(){},_parseData:function(){},_click:function(){},_select:function(){},_change:function(){},_changeAll:function(){},_setupPermissions:function(){},_savePermissions:function(){},submit:function(){},_save:function(){}}); })(this);
// WCF.Attachment.js
-(function (window, undefined) { "use strict";WCF.Attachment={},WCF.Attachment.Upload=WCF.Upload.extend({_autoInsert:[],_insertAllButton:null,_objectType:"",_objectID:0,_tmpHash:"",_parentObjectID:0,_editorId:"",_replaceOnLoad:{},_options:{},init:function(t,e,i,a,n,s,r,l,o){var d,c;this._super(t,e,"wcf\\data\\attachment\\AttachmentAction",{multiple:!0,maxUploads:r}),this._autoInsert=[],this._objectType=i,this._objectID=parseInt(a),this._tmpHash=n,this._parentObjectID=parseInt(s),this._editorId=l,this._options=$.extend(!0,this._options,o||{}),this._buttonSelector.children("p.button").click($.proxy(this._validateLimit,this)),this._fileListSelector.find(".jsButtonInsertAttachment").click($.proxy(this._insert,this)),this._fileListSelector.find(".jsButtonAttachmentInsertThumbnail").click($.proxy(this._insert,this)),this._fileListSelector.find(".jsButtonAttachmentInsertFull").click($.proxy(this._insert,this)),WCF.System.Event.addListener("com.woltlab.wcf.action.delete","attachment",this._onDelete.bind(this)),this._makeSortable(),this._insertAllButton=$('<p class="button jsButtonAttachmentInsertAll">'+WCF.Language.get("wcf.attachment.insertAll")+"</p>").hide(),this._editorId&&(this._insertAllButton.appendTo(this._buttonSelector),this._insertAllButton.click($.proxy(this._insertAll,this)),this._fileListSelector.children("li:not(.uploadFailed)").length&&this._insertAllButton.show(),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)),WCF.System.Event.addListener("com.woltlab.wcf.redactor2","autosaveMetaData_"+this._editorId,function(t){t.tmpHashes&&Array.isArray(t.tmpHashes)||(t.tmpHashes=[]);var e=t.tmpHashes.indexOf(n);0<this._fileListSelector.children("li:not(.uploadFailed)").length?-1===e&&t.tmpHashes.push(n):-1!==e&&t.tmpHashes.splice(e)}.bind(this)),d=WCF.System.Event.addListener("com.woltlab.wcf.redactor2","metacode_attach_"+this._editorId,function(t){var e,i,a,n,s,r=this._getImageAttachments(),l=t.attributes[0]||0;r.hasOwnProperty(l)&&(e=~~$("#"+this._editorId).data("redactor").opts.woltlab.attachmentThumbnailWidth,i=!0===(i=t.attributes[2])||"true"===i||~~i&&~~i<=e,(a=elCreate("img")).className="woltlabAttachment",a.src=r[l][i?"thumbnailUrl":"url"],elData(a,"attachment-id",l),"left"===(n=t.attributes[1]||"none")?a.classList.add("messageFloatObjectLeft"):"right"===n&&a.classList.add("messageFloatObjectRight"),(s=t.metacode).parentNode.insertBefore(a,s),elRemove(s),t.cancel=!0)}.bind(this)),c=WCF.System.Event.addListener("com.woltlab.wcf.redactor2","sync_"+this._tmpHash,this._sync.bind(this)),WCF.System.Event.addListener("com.woltlab.wcf.redactor2","destroy_"+this._editorId,function(){WCF.System.Event.removeAllListeners("com.woltlab.wcf.redactor2","submit_"+this._editorId),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.removeAllListeners("com.woltlab.wcf.redactor2","autosaveMetaData_"+this._editorId),WCF.System.Event.removeListener("com.woltlab.wcf.redactor2","metacode_attach_"+this._editorId,d),WCF.System.Event.removeListener("com.woltlab.wcf.redactor2","sync_"+this._tmpHash,c)}.bind(this)))},_editorUpload:function(e){var i=null;this._fileListSelector.closest(".messageTabMenu").messageTabMenu("showTab","attachments",!0);var t=function(t){null===i?this._autoInsert.push(t):this._replaceOnLoad[t]=i,e.uploadID=t}.bind(this);e.file?this._upload(void 0,e.file,void 0,t):(this._upload(void 0,void 0,e.blob,t),i=e.replace||null)},_getImageAttachments:function(){var a={};return this._fileListSelector.children("li").each(function(t,e){var i=$(e);i.data("isImage")&&(a[~~i.data("objectID")]={thumbnailUrl:i.find(".jsButtonAttachmentInsertThumbnail").data("url"),url:i.find(".jsButtonAttachmentInsertFull").data("url")})}),a},_submitInline:function(t){var e;this._tmpHash&&(t.tmpHash=this._tmpHash,e={},WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","getMetaData_"+this._editorId,e),e.tmpHashes&&Array.isArray(e.tmpHashes)&&0<e.tmpHashes.length&&(t.tmpHash+=","+e.tmpHashes.join(",")))},_reset:function(){this._fileListSelector.hide().empty(),this._insertAllButton.hide(),this._validateLimit()},_validateLimit:function(){var t=this._buttonSelector.next("small.innerError"),e=this._options.maxUploads-this._fileListSelector.children("li:not(.uploadFailed)").length,i=this._fileUpload?this._fileUpload.prop("files").length:0;if(e<=0||e<i){var a=e<=0?WCF.Language.get("wcf.attachment.upload.error.reachedLimit"):WCF.Language.get("wcf.attachment.upload.error.reachedRemainingLimit").replace(/#remaining#/,e);return t.length||(t=$('<small class="innerError" />').insertAfter(this._buttonSelector)),t.html(a),!1}return t.remove(),!0},_removeLimitError:function(t){var e=this._fileListSelector.children("li");e.filter(":not(.uploadFailed)").length||this._insertAllButton.hide(),e.length||this._fileListSelector.hide(),this._editorId&&t.button&&WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","deleteAttachment_"+this._editorId,{attachmentId:t.button.data("objectID")})},_upload:function(s,r,l,o){var m=this._super.bind(this);require(["WoltLabSuite/Core/FileUtil","WoltLabSuite/Core/Image/ImageUtil","WoltLabSuite/Core/Image/Resizer","WoltLabSuite/Core/Ajax/Status"],function(t,d,e,i){i.show();var a=[];r?a.push(r):l?a.push(t.blobToFile(l,"pasted-from-clipboard")):a=this._fileUpload.prop("files");var c,h,n=Promise.resolve(a);this._options.autoScale&&this._options.autoScale.enable&&(c=this._buttonSelector.data("maxSize"),h=new e,n=Array.prototype.reduce.call(a,function(t,o){return t.then(function(e){if(-1===["image/png","image/jpeg"].indexOf(o.type))return e.push(o),e;var l=new Promise(function(t,e){setTimeout(function(){t(o)},1e4)}),t=h.loadFile(o).then(function(t){var e,i,a=t.exif,n=this._options.autoScale.maxWidth,s=this._options.autoScale.maxHeight,r=this._options.autoScale.quality;return 2<=window.devicePixelRatio&&(e=window.screen.width*window.devicePixelRatio,i=window.screen.height*window.devicePixelRatio,e-10<t.image.width&&t.image.width<10+e&&i-10<t.image.height&&(n=Math.min(n,window.screen.width))),h.resize(t.image,n,s,r,o.size>c,l).then(function(t){if(void 0===t)return o;var e=this._options.autoScale.fileType;return"keep"!==this._options.autoScale.fileType&&!d.containsTransparentPixels(t)||(e=o.type),h.saveFile({exif:a,image:t},o.name,e,r)}.bind(this)).then(function(t){return t.size>o.size?(console.debug('[WCF.Attachment] File size of "'+o.name+'" increased, uploading untouched image.'),o):t})}.bind(this)).catch(function(t){return console.debug('[WCF.Attachment] Failed to resize image "'+o.name+'":',t),o});return Promise.race([l,t]).then(function(t){return e.push(t),e})}.bind(this))}.bind(this),Promise.resolve([]))),n.then(function(t){var e=void 0;return this._validateLimit()&&(e=m(s,void 0,void 0,t)),this._fileUpload&&(this._removeButton(),this._createButton()),"function"==typeof o&&o(e),e}.bind(this)).catch(function(t){console.debug("[WCF.Attachment] Failed to upload attachments:",t)}).finally(i.hide)}.bind(this),function(t){console.debug("[WCF.Attachment] Failed to load modules:",t)})},_createUploadMatrix:function(t){return this._fileListSelector.children("li.uploadFailed").remove(),this._super(t)},_getParameters:function(){return{objectType:this._objectType,objectID:this._objectID,tmpHash:this._tmpHash,parentObjectID:this._parentObjectID}},_initFile:function(t){var e=$('<li class="box64 formAttachmentListItem"><span class="icon icon64 fa-spinner" /><div><div><p>'+t.name+'</p><small><progress max="100"></progress></small></div><ul></ul></div></li>').data("filename",t.name);return this._fileListSelector.append(e),this._fileListSelector.show(),this._buttonSelector.data("maxSize")<t.size&&(e.find("progress").remove(),e.children(".fa-spinner").removeClass("fa-spinner").addClass("fa-ban"),e.find("div > div").append($('<small class="innerError">'+WCF.Language.get("wcf.attachment.upload.error.tooLarge")+"</small>")),e.addClass("uploadFailed")),e},_useThumbnail:function(){return!0},_success:function(t,e){var i,a,n,s,r,l,o,d,c,h,m;for(var u in this._uploadMatrix[t]){this._uploadMatrix[t].hasOwnProperty(u)&&((a=this._uploadMatrix[t][u]).find("progress").remove(),n=a.data("filename"),s=a.data("internalFileID"),e.returnValues&&e.returnValues.attachments[s]?(i=e.returnValues.attachments[s],elData(a[0],"object-id",i.attachmentID),i.tinyURL?(a.children(".fa-spinner").replaceWith($('<img src="'+i.tinyURL+'" alt="" class="attachmentTinyThumbnail" />')),a.data("height",i.height),a.data("width",i.width),elData(a[0],"is-image",i.isImage)):a.children(".fa-spinner").removeClass("fa-spinner").addClass("fa-"+i.iconName),(r=$('<a href=""></a>')).text(n).attr("href",i.url),r[0].target="_blank",0!=i.isImage&&r.addClass("jsImageViewer").attr("title",n),a.find("p").empty().append(r),a.find("small").append(i.formattedFilesize),l=a.find("ul").addClass("buttonGroup"),o=$('<li><span class="button small jsDeleteButton" data-object-id="'+i.attachmentID+'" data-confirm-message="'+WCF.Language.get("wcf.attachment.delete.sure")+'" data-event-name="attachment">'+WCF.Language.get("wcf.global.button.delete")+"</span></li>"),l.append(o),a.data("objectID",i.attachmentID),this._editorId&&(i.tinyURL?(i.thumbnailURL&&$('<li><span class="button small jsButtonAttachmentInsertThumbnail" data-object-id="'+i.attachmentID+'" data-url="'+WCF.String.escapeHTML(i.thumbnailURL)+'">'+WCF.Language.get("wcf.attachment.insertThumbnail")+"</span></li>").appendTo(l),$('<li><span class="button small jsButtonAttachmentInsertFull" data-object-id="'+i.attachmentID+'" data-url="'+WCF.String.escapeHTML(i.url)+'">'+WCF.Language.get("wcf.attachment.insertFull")+"</span></li>").appendTo(l)):$('<li><span class="button small jsButtonAttachmentInsertPlain" data-object-id="'+i.attachmentID+'">'+WCF.Language.get("wcf.attachment.insert")+"</span></li>").appendTo(l)),this._triggerSync("new",{html:a[0].outerHTML}),this._registerEditorButtons(a[0]),this._replaceOnLoad.hasOwnProperty(t)&&(a.hasClass("uploadFailed")||(d=this._replaceOnLoad[t])&&d.parentNode&&WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","replaceAttachment_"+this._editorId,{attachmentId:i.attachmentID,img:d,src:i.thumbnailURL?i.thumbnailURL:i.url}),this._replaceOnLoad[t]=null)):(a.children(".fa-spinner").removeClass("fa-spinner").addClass("fa-ban"),h="",e.returnValues&&e.returnValues.errors[s]?"uploadFailed"===(h=(c=e.returnValues.errors[s]).errorType)&&c.additionalData.phpLimitExceeded&&(h="uploadPhpLimit"):h="uploadFailed",a.find("div > div").append($('<small class="innerError">'+WCF.Language.get("wcf.attachment.upload.error."+h)+"</small>")),a.addClass("uploadFailed")),WCF.inArray(t,this._autoInsert)&&(this._autoInsert.splice(this._autoInsert.indexOf(t),1),a.hasClass("uploadFailed")||((m=a.find(".jsButtonAttachmentInsertThumbnail")).length||(m=a.find(".jsButtonAttachmentInsertFull")),m.trigger("click"))))}this._rebuildInterface()},_rebuildInterface:function(){this._makeSortable(),this._fileListSelector.children("li:not(.uploadFailed)").length?this._insertAllButton.show():this._insertAllButton.hide(),WCF.DOMNodeInsertedHandler.execute()},_registerEditorButtons:function(t){this._editorId&&elBySelAll(".jsButtonAttachmentInsertThumbnail, .jsButtonAttachmentInsertFull, .jsButtonAttachmentInsertPlain",t,function(t){t.addEventListener("click",this._insert.bind(this))}.bind(this))},_insert:function(t){WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","insertAttachment_"+this._editorId,{attachmentId:elData(t.currentTarget,"object-id"),url:elData(t.currentTarget,"url")})},_insertAll:function(){for(var t,e,i=0,a=this._fileListSelector[0].childNodes.length;i<a;i++)"LI"!==(t=this._fileListSelector[0].childNodes[i]).nodeName||t.classList.contains("uploadFailed")||(null===(e=elBySel(".jsButtonAttachmentInsertThumbnail, .jsButtonAttachmentInsertPlain",t))&&(e=elBySel(".jsButtonAttachmentInsertFull, .jsButtonAttachmentInsertPlain",t)),window.jQuery(e).trigger("click"))},_error:function(a){this._fileListSelector.find("li").each(function(t,e){var i=$(e);i.children(".fa-spinner").length&&(i.addClass("uploadFailed").children(".fa-spinner").removeClass("fa-spinner").addClass("fa-ban"),i.find("div > div").append($('<small class="innerError">'+(a.responseJSON&&a.responseJSON.message?a.responseJSON.message:WCF.Language.get("wcf.attachment.upload.error.uploadFailed"))+"</small>")))})},_makeSortable:function(){var t=this._fileListSelector.children("li:not(.uploadFailed)");t.length&&(t.addClass("sortableAttachment").children("img").addClass("sortableNode"),this._fileListSelector.hasClass("sortableList")||(this._fileListSelector.addClass("sortableList"),require(["Environment"],function(t){"desktop"===t.platform()&&new WCF.Sortable.List(this._fileListSelector.parent().wcfIdentify(),"",0,{axis:!1,items:"li.sortableAttachment",toleranceElement:null,start:function(t,e){e.placeholder[0].style.setProperty("height",e.helper[0].offsetHeight+"px","")},update:function(){var i=[];this._fileListSelector.children("li:not(.uploadFailed)").each(function(t,e){i.push($(e).data("objectID"))}),i.length&&new WCF.Action.Proxy({autoSend:!0,data:{actionName:"updatePosition",className:"wcf\\data\\attachment\\AttachmentAction",parameters:{attachmentIDs:i,objectID:this._objectID,objectType:this._objectType,tmpHash:this._tmpHash}}})}.bind(this)},!0)}.bind(this))))},_onDelete:function(t){var e=elData(t.button[0],"object-id"),i=elBySel('.formAttachmentListItem[data-object-id="'+e+'"]',this._fileListSelector[0]);null!==i&&elRemove(i),this._removeLimitError(t)},_sync:function(t){if(t.source!==this)switch(t.type){case"new":this._syncNew(t.data);break;default:throw new Error("Unexpected type '"+t.type+"'")}},_syncNew:function(a){require(["Dom/Util"],function(t){var e=t.createFragmentFromHtml(a.html),i=elBySel("li",e);i.id="",this._registerEditorButtons(i),this._fileListSelector[0].appendChild(i),elShow(this._fileListSelector[0]),this._rebuildInterface()}.bind(this))},_triggerSync:function(t,e){WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","sync_"+this._tmpHash,{source:this,type:t,data:e})}}); })(this);
+(function (window, undefined) { "use strict";WCF.Attachment={},WCF.Attachment.Upload=WCF.Upload.extend({_autoInsert:[],_insertAllButton:null,_objectType:"",_objectID:0,_tmpHash:"",_parentObjectID:0,_editorId:"",_replaceOnLoad:{},_options:{},init:function(t,e,i,a,n,s,r,l,o){var d,c;this._super(t,e,"wcf\\data\\attachment\\AttachmentAction",{multiple:!0,maxUploads:r}),this._autoInsert=[],this._objectType=i,this._objectID=parseInt(a),this._tmpHash=n,this._parentObjectID=parseInt(s),this._editorId=l,this._options=$.extend(!0,this._options,o||{}),this._buttonSelector.children("p.button").click($.proxy(this._validateLimit,this)),this._fileListSelector.find(".jsButtonInsertAttachment").click($.proxy(this._insert,this)),this._fileListSelector.find(".jsButtonAttachmentInsertThumbnail").click($.proxy(this._insert,this)),this._fileListSelector.find(".jsButtonAttachmentInsertFull").click($.proxy(this._insert,this)),WCF.System.Event.addListener("com.woltlab.wcf.action.delete","attachment",this._onDelete.bind(this)),this._makeSortable(),this._insertAllButton=$('<p class="button jsButtonAttachmentInsertAll">'+WCF.Language.get("wcf.attachment.insertAll")+"</p>").hide(),this._editorId&&(this._insertAllButton.appendTo(this._buttonSelector),this._insertAllButton.click($.proxy(this._insertAll,this)),this._fileListSelector.children("li:not(.uploadFailed)").length&&this._insertAllButton.show(),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)),WCF.System.Event.addListener("com.woltlab.wcf.redactor2","autosaveMetaData_"+this._editorId,function(t){t.tmpHashes&&Array.isArray(t.tmpHashes)||(t.tmpHashes=[]);var e=t.tmpHashes.indexOf(n);0<this._fileListSelector.children("li:not(.uploadFailed)").length?-1===e&&t.tmpHashes.push(n):-1!==e&&t.tmpHashes.splice(e)}.bind(this)),d=WCF.System.Event.addListener("com.woltlab.wcf.redactor2","metacode_attach_"+this._editorId,function(t){var e,i,a,n,s,r=this._getImageAttachments(),l=t.attributes[0]||0;r.hasOwnProperty(l)&&(e=~~$("#"+this._editorId).data("redactor").opts.woltlab.attachmentThumbnailWidth,i=!0===(i=t.attributes[2])||"true"===i||~~i&&~~i<=e,(a=elCreate("img")).className="woltlabAttachment",a.src=r[l][i?"thumbnailUrl":"url"],elData(a,"attachment-id",l),"left"===(n=t.attributes[1]||"none")?a.classList.add("messageFloatObjectLeft"):"right"===n&&a.classList.add("messageFloatObjectRight"),(s=t.metacode).parentNode.insertBefore(a,s),elRemove(s),t.cancel=!0)}.bind(this)),c=WCF.System.Event.addListener("com.woltlab.wcf.redactor2","sync_"+this._tmpHash,this._sync.bind(this)),WCF.System.Event.addListener("com.woltlab.wcf.redactor2","destroy_"+this._editorId,function(){WCF.System.Event.removeAllListeners("com.woltlab.wcf.redactor2","submit_"+this._editorId),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.removeAllListeners("com.woltlab.wcf.redactor2","autosaveMetaData_"+this._editorId),WCF.System.Event.removeListener("com.woltlab.wcf.redactor2","metacode_attach_"+this._editorId,d),WCF.System.Event.removeListener("com.woltlab.wcf.redactor2","sync_"+this._tmpHash,c)}.bind(this)))},_editorUpload:function(e){var i=null;this._fileListSelector.closest(".messageTabMenu").messageTabMenu("showTab","attachments",!0);var t=function(t){null===i?this._autoInsert.push(t):this._replaceOnLoad[t]=i,e.uploadID=t}.bind(this);e.file?this._upload(void 0,e.file,void 0,t):(this._upload(void 0,void 0,e.blob,t),i=e.replace||null)},_getImageAttachments:function(){var a={};return this._fileListSelector.children("li").each(function(t,e){var i=$(e);i.data("isImage")&&(a[~~i.data("objectID")]={thumbnailUrl:i.find(".jsButtonAttachmentInsertThumbnail").data("url"),url:i.find(".jsButtonAttachmentInsertFull").data("url")})}),a},_submitInline:function(t){var e;this._tmpHash&&(t.tmpHash=this._tmpHash,e={},WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","getMetaData_"+this._editorId,e),e.tmpHashes&&Array.isArray(e.tmpHashes)&&0<e.tmpHashes.length&&(t.tmpHash+=","+e.tmpHashes.join(",")))},_reset:function(){this._fileListSelector.hide().empty(),this._insertAllButton.hide(),this._validateLimit()},_validateLimit:function(){var t=this._buttonSelector.next("small.innerError"),e=this._options.maxUploads-this._fileListSelector.children("li:not(.uploadFailed)").length,i=this._fileUpload?this._fileUpload.prop("files").length:0;if(e<=0||e<i){var a=e<=0?WCF.Language.get("wcf.attachment.upload.error.reachedLimit"):WCF.Language.get("wcf.attachment.upload.error.reachedRemainingLimit").replace(/#remaining#/,e);return t.length||(t=$('<small class="innerError" />').insertAfter(this._buttonSelector)),t.html(a),!1}return t.remove(),!0},_removeLimitError:function(t){var e=this._fileListSelector.children("li");e.filter(":not(.uploadFailed)").length||this._insertAllButton.hide(),e.length||this._fileListSelector.hide(),this._editorId&&t.button&&WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","deleteAttachment_"+this._editorId,{attachmentId:t.button.data("objectID")})},_upload:function(s,r,l,o){var m=this._super.bind(this);require(["WoltLabSuite/Core/FileUtil","WoltLabSuite/Core/Image/ImageUtil","WoltLabSuite/Core/Image/Resizer","WoltLabSuite/Core/Ajax/Status"],function(t,d,e,i){i.show();var a=[];r?a.push(r):l?a.push(t.blobToFile(l,"pasted-from-clipboard")):a=this._fileUpload.prop("files");var c,h,n=Promise.resolve(a);this._options.autoScale&&this._options.autoScale.enable&&(c=this._buttonSelector.data("maxSize"),h=new e,n=Array.prototype.reduce.call(a,function(t,o){return t.then(function(e){if(-1===["image/png","image/jpeg"].indexOf(o.type))return e.push(o),e;var l=new Promise(function(t,e){setTimeout(function(){t(o)},1e4)}),t=h.loadFile(o).then(function(t){var e,i,a=t.exif,n=this._options.autoScale.maxWidth,s=this._options.autoScale.maxHeight,r=this._options.autoScale.quality;return 2<=window.devicePixelRatio&&(e=window.screen.width*window.devicePixelRatio,i=window.screen.height*window.devicePixelRatio,e-10<t.image.width&&t.image.width<10+e&&i-10<t.image.height&&(n=Math.min(n,window.screen.width))),h.resize(t.image,n,s,r,o.size>c,l).then(function(t){if(void 0===t)return o;var e=this._options.autoScale.fileType;return"keep"!==this._options.autoScale.fileType&&!d.containsTransparentPixels(t)||(e=o.type),h.saveFile({exif:a,image:t},o.name,e,r)}.bind(this)).then(function(t){return t.size>o.size?(console.debug('[WCF.Attachment] File size of "'+o.name+'" increased, uploading untouched image.'),o):t})}.bind(this)).catch(function(t){return console.debug('[WCF.Attachment] Failed to resize image "'+o.name+'":',t),o});return Promise.race([l,t]).then(function(t){return e.push(t),e})}.bind(this))}.bind(this),Promise.resolve([]))),n.then(function(t){var e=void 0;return this._validateLimit()&&(e=m(s,void 0,void 0,t)),this._fileUpload&&(this._removeButton(),this._createButton()),"function"==typeof o&&o(e),e}.bind(this)).catch(function(t){console.debug("[WCF.Attachment] Failed to upload attachments:",t)}).finally(i.hide)}.bind(this),function(t){console.debug("[WCF.Attachment] Failed to load modules:",t)})},_createUploadMatrix:function(t){return this._fileListSelector.children("li.uploadFailed").remove(),this._super(t)},_getParameters:function(){return{objectType:this._objectType,objectID:this._objectID,tmpHash:this._tmpHash,parentObjectID:this._parentObjectID}},_initFile:function(t){var e=$('<li class="box64 formAttachmentListItem"><span class="icon icon64 fa-spinner" /><div><div><p>'+WCF.String.escapeHTML(t.name)+'</p><small><progress max="100"></progress></small></div><ul></ul></div></li>').data("filename",t.name);return this._fileListSelector.append(e),this._fileListSelector.show(),this._buttonSelector.data("maxSize")<t.size&&(e.find("progress").remove(),e.children(".fa-spinner").removeClass("fa-spinner").addClass("fa-ban"),e.find("div > div").append($('<small class="innerError">'+WCF.Language.get("wcf.attachment.upload.error.tooLarge")+"</small>")),e.addClass("uploadFailed")),e},_useThumbnail:function(){return!0},_success:function(t,e){var i,a,n,s,r,l,o,d,c,h,m;for(var u in this._uploadMatrix[t]){this._uploadMatrix[t].hasOwnProperty(u)&&((a=this._uploadMatrix[t][u]).find("progress").remove(),n=a.data("filename"),s=a.data("internalFileID"),e.returnValues&&e.returnValues.attachments[s]?(i=e.returnValues.attachments[s],elData(a[0],"object-id",i.attachmentID),i.tinyURL?(a.children(".fa-spinner").replaceWith($('<img src="'+i.tinyURL+'" alt="" class="attachmentTinyThumbnail" />')),a.data("height",i.height),a.data("width",i.width),elData(a[0],"is-image",i.isImage)):a.children(".fa-spinner").removeClass("fa-spinner").addClass("fa-"+i.iconName),(r=$('<a href=""></a>')).text(n).attr("href",i.url),r[0].target="_blank",0!=i.isImage&&r.addClass("jsImageViewer").attr("title",n),a.find("p").empty().append(r),a.find("small").append(i.formattedFilesize),l=a.find("ul").addClass("buttonGroup"),o=$('<li><span class="button small jsDeleteButton" data-object-id="'+i.attachmentID+'" data-confirm-message="'+WCF.Language.get("wcf.attachment.delete.sure")+'" data-event-name="attachment">'+WCF.Language.get("wcf.global.button.delete")+"</span></li>"),l.append(o),a.data("objectID",i.attachmentID),this._editorId&&(i.tinyURL?(i.thumbnailURL&&$('<li><span class="button small jsButtonAttachmentInsertThumbnail" data-object-id="'+i.attachmentID+'" data-url="'+WCF.String.escapeHTML(i.thumbnailURL)+'">'+WCF.Language.get("wcf.attachment.insertThumbnail")+"</span></li>").appendTo(l),$('<li><span class="button small jsButtonAttachmentInsertFull" data-object-id="'+i.attachmentID+'" data-url="'+WCF.String.escapeHTML(i.url)+'">'+WCF.Language.get("wcf.attachment.insertFull")+"</span></li>").appendTo(l)):$('<li><span class="button small jsButtonAttachmentInsertPlain" data-object-id="'+i.attachmentID+'">'+WCF.Language.get("wcf.attachment.insert")+"</span></li>").appendTo(l)),this._triggerSync("new",{html:a[0].outerHTML}),this._registerEditorButtons(a[0]),this._replaceOnLoad.hasOwnProperty(t)&&(a.hasClass("uploadFailed")||(d=this._replaceOnLoad[t])&&d.parentNode&&WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","replaceAttachment_"+this._editorId,{attachmentId:i.attachmentID,img:d,src:i.thumbnailURL?i.thumbnailURL:i.url}),this._replaceOnLoad[t]=null)):(a.children(".fa-spinner").removeClass("fa-spinner").addClass("fa-ban"),h="",e.returnValues&&e.returnValues.errors[s]?"uploadFailed"===(h=(c=e.returnValues.errors[s]).errorType)&&c.additionalData.phpLimitExceeded&&(h="uploadPhpLimit"):h="uploadFailed",a.find("div > div").append($('<small class="innerError">'+WCF.Language.get("wcf.attachment.upload.error."+h)+"</small>")),a.addClass("uploadFailed")),WCF.inArray(t,this._autoInsert)&&(this._autoInsert.splice(this._autoInsert.indexOf(t),1),a.hasClass("uploadFailed")||((m=a.find(".jsButtonAttachmentInsertThumbnail")).length||(m=a.find(".jsButtonAttachmentInsertFull")),m.trigger("click"))))}this._rebuildInterface()},_rebuildInterface:function(){this._makeSortable(),this._fileListSelector.children("li:not(.uploadFailed)").length?this._insertAllButton.show():this._insertAllButton.hide(),WCF.DOMNodeInsertedHandler.execute()},_registerEditorButtons:function(t){this._editorId&&elBySelAll(".jsButtonAttachmentInsertThumbnail, .jsButtonAttachmentInsertFull, .jsButtonAttachmentInsertPlain",t,function(t){t.addEventListener("click",this._insert.bind(this))}.bind(this))},_insert:function(t){WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","insertAttachment_"+this._editorId,{attachmentId:elData(t.currentTarget,"object-id"),url:elData(t.currentTarget,"url")})},_insertAll:function(){for(var t,e,i=0,a=this._fileListSelector[0].childNodes.length;i<a;i++)"LI"!==(t=this._fileListSelector[0].childNodes[i]).nodeName||t.classList.contains("uploadFailed")||(null===(e=elBySel(".jsButtonAttachmentInsertThumbnail, .jsButtonAttachmentInsertPlain",t))&&(e=elBySel(".jsButtonAttachmentInsertFull, .jsButtonAttachmentInsertPlain",t)),window.jQuery(e).trigger("click"))},_error:function(a){this._fileListSelector.find("li").each(function(t,e){var i=$(e);i.children(".fa-spinner").length&&(i.addClass("uploadFailed").children(".fa-spinner").removeClass("fa-spinner").addClass("fa-ban"),i.find("div > div").append($('<small class="innerError">'+(a.responseJSON&&a.responseJSON.message?a.responseJSON.message:WCF.Language.get("wcf.attachment.upload.error.uploadFailed"))+"</small>")))})},_makeSortable:function(){var t=this._fileListSelector.children("li:not(.uploadFailed)");t.length&&(t.addClass("sortableAttachment").children("img").addClass("sortableNode"),this._fileListSelector.hasClass("sortableList")||(this._fileListSelector.addClass("sortableList"),require(["Environment"],function(t){"desktop"===t.platform()&&new WCF.Sortable.List(this._fileListSelector.parent().wcfIdentify(),"",0,{axis:!1,items:"li.sortableAttachment",toleranceElement:null,start:function(t,e){e.placeholder[0].style.setProperty("height",e.helper[0].offsetHeight+"px","")},update:function(){var i=[];this._fileListSelector.children("li:not(.uploadFailed)").each(function(t,e){i.push($(e).data("objectID"))}),i.length&&new WCF.Action.Proxy({autoSend:!0,data:{actionName:"updatePosition",className:"wcf\\data\\attachment\\AttachmentAction",parameters:{attachmentIDs:i,objectID:this._objectID,objectType:this._objectType,tmpHash:this._tmpHash}}})}.bind(this)},!0)}.bind(this))))},_onDelete:function(t){var e=elData(t.button[0],"object-id"),i=elBySel('.formAttachmentListItem[data-object-id="'+e+'"]',this._fileListSelector[0]);null!==i&&elRemove(i),this._removeLimitError(t)},_sync:function(t){if(t.source!==this)switch(t.type){case"new":this._syncNew(t.data);break;default:throw new Error("Unexpected type '"+t.type+"'")}},_syncNew:function(a){require(["Dom/Util"],function(t){var e=t.createFragmentFromHtml(a.html),i=elBySel("li",e);i.id="",this._registerEditorButtons(i),this._fileListSelector[0].appendChild(i),elShow(this._fileListSelector[0]),this._rebuildInterface()}.bind(this))},_triggerSync:function(t,e){WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","sync_"+this._tmpHash,{source:this,type:t,data:e})}}); })(this);
// WCF.ColorPicker.js
(function (window, undefined) { "use strict";WCF.ColorPicker=Class.extend({_bar:{},_barActive:!1,_barSelector:{},_dialog:{},_didInit:!1,_elementID:"",_gradient:{},_gradientActive:!1,_gradientSelector:{},_hex:{},_hsv:{},_newColor:{},_oldColor:{},_rgba:{},_rgbaRegExp:{},init:function(){},_open:function(){},_parseColor:function(){},_initColorPicker:function(){},_initColorPickerForm:function(){},_keyUpRGBA:function(){},_keyUpHex:function(){},_submit:function(){},_createInputElement:function(){},_mouseDownGradient:function(){},_mouseGradient:function(){},_mouseDownBar:function(){},_mouseBar:function(){},_blurRgba:function(){},_blurHex:function(){},_updateValues:function(){},hsvToRgb:function(n,o,t){return window.__wcf_bc_colorUtil.hsvToRgb(n,o,t)},rgbToHsv:function(n,o,t){return window.__wcf_bc_colorUtil.rgbToHsv(n,o,t)},hexToRgb:function(n){return window.__wcf_bc_colorUtil.hexToRgb(n)},rgbToHex:function(n,o,t){return window.__wcf_bc_colorUtil.rgbToHex(n,o,t)}}); })(this);