// WoltLabAttachment.js
$.Redactor.prototype.WoltLabAttachment=function(){"use strict";return{init:function(){require(["EventHandler"],function(t){t.add("com.woltlab.wcf.redactor2","insertAttachment_"+this.$element[0].id,this.WoltLabAttachment._insert.bind(this)),t.add("com.woltlab.wcf.redactor2","deleteAttachment_"+this.$element[0].id,this.WoltLabAttachment._delete.bind(this))}.bind(this))},_insert:function(t){var e=t.attachmentId;this.buffer.set(),t.url?this.insert.html('<img src="'+t.url+'" class="woltlabAttachment" data-attachment-id="'+e+'">'):this.insert.text("[attach="+e+"][/attach]")},_delete:function(t){var e=t.attachmentId,a=this.core.editor()[0];elBySelAll('.woltlabAttachment[data-attachment-id="'+e+'"]',a,function(t){elRemove(t)});var n="[attach="+e+"][/attach]";if(a.textContent.indexOf(n)!==!1){for(var i,c=document.createTreeWalker(a,NodeFilter.SHOW_TEXT,null,!1),r=[];i=c.nextNode();)-1!==i.textContent.indexOf(n)&&r.push(i);for(var l=0,o=r.length;o>l;l++)r[l].textContent=r[l].textContent.replace(new RegExp("\\[attach="+e+"\\]\\[\\/attach\\]","g"),"")}}}};
// WoltLabButton.js
-$.Redactor.prototype.WoltLabButton=function(){"use strict";return{init:function(){for(var t,o,s,e=0,n=this.opts.buttons.length;n>e;e++)s=this.opts.buttons[e],"wcfSeparator"!==s&&(o=this.opts.woltlab.buttons[s],"subscript"===s||"superscript"===s?(t=this.button.addAfter(this.opts.buttons[e-1],s,""),this.button.setEvent(t,s,{func:"inline.format"})):t=this.button.get(s),this.button.setIcon(t,'<span class="icon icon16 '+o.icon+'"></span>'),t[0]||console.debug(s),elAttr(t[0],"title",o.title),t[0].classList.add("jsTooltip"));for(var i,r={},a=[],l=this.core.toolbar()[0];l.childElementCount;)i=l.removeChild(l.children[0]),s=elAttr(i.children[0],"rel"),r[s]=i,a.push(s);var c=!1;for(e=0,n=this.opts.buttons.length;n>e;e++)s=this.opts.buttons[e],"wcfSeparator"!==s?(i=r[s],l.appendChild(i),a.splice(a.indexOf(s),1),c&&(i.classList.add("redactor-toolbar-separator"),c=!1)):c=!0;a.forEach(function(t){l.appendChild(r[t])}),WCF.DOMNodeInsertedHandler.execute()}}};
+$.Redactor.prototype.WoltLabButton=function(){"use strict";return{init:function(){for(var t,o,s,n=0,i=this.opts.buttons.length;i>n;n++)if(s=this.opts.buttons[n],"wcfSeparator"!==s){if(!this.opts.woltlab.buttons.hasOwnProperty(s))throw new Error("Missing button definition for '"+s+"'.");if(o=this.opts.woltlab.buttons[s],"subscript"===s||"superscript"===s?(t=this.button.addAfter(this.opts.buttons[n-1],s,""),this.button.setEvent(t,s,{func:"inline.format"})):t=this.button.get(s),this.button.setIcon(t,'<span class="icon icon16 '+o.icon+'"></span>'),!t[0])throw new Error("Missing button element for '"+s+"'.");elAttr(t[0],"title",o.title),t[0].classList.add("jsTooltip")}for(var r,e={},a=[],l=this.core.toolbar()[0];l.childElementCount;)r=l.removeChild(l.children[0]),s=elAttr(r.children[0],"rel"),e[s]=r,a.push(s);var c=!1;for(n=0,i=this.opts.buttons.length;i>n;n++)s=this.opts.buttons[n],"wcfSeparator"!==s?(r=e[s],l.appendChild(r),a.splice(a.indexOf(s),1),c&&(r.classList.add("redactor-toolbar-separator"),c=!1)):c=!0;a.forEach(function(t){l.appendChild(e[t])}),WCF.DOMNodeInsertedHandler.execute()}}};
// WoltLabColor.js
$.Redactor.prototype.WoltLabColor=function(){"use strict";return{init:function(){for(var o,t=["000000","800000","8B4513","2F4F4F","008080","000080","4B0082","696969","B22222","A52A2A","DAA520","006400","40E0D0","0000CD","800080","808080","FF0000","FF8C00","FFD700","008000","00FFFF","0000FF","EE82EE","A9A9A9","FFA07A","FFA500","FFFF00","00FF00","AFEEEE","ADD8E6","DDA0DD","D3D3D3","FFF0F5","FAEBD7","FFFFE0","F0FFF0","F0FFFF","F0F8FF","E6E6FA","FFFFFF"],F=this.WoltLabColor.setColor.bind(this),r={removeColor:{title:"remove color",func:this.WoltLabColor.removeColor.bind(this)}},e=0,l=t.length;l>e;e++)o=t[e],r["color_"+o]={title:"#"+o,func:F};var i=this.button.add("woltlabColor","");this.button.addDropdown(i,r),i.data("dropdown").find("a").each(function(o,t){t.className.match(/redactor-dropdown-color_([A-F0-9]{6})/)&&(t.parentNode.classList.add("woltlab-color-"+RegExp.$1),t.parentNode.classList.add("woltlab-color-selection"))})},setColor:function(o){o=o.replace(/^color_/,""),require(["WoltLab/WCF/Ui/Redactor/Format"],function(t){this.selection.save(),t.format(this.$editor[0],"woltlab-color","woltlab-color-"+o),this.selection.restore()}.bind(this))},removeColor:function(){require(["WoltLab/WCF/Ui/Redactor/Format"],function(o){this.selection.save(),o.removeFormat(this.$editor[0],"woltlab-color"),this.selection.restore()}.bind(this))}}};
// WoltLabDropdown.js
// WoltLabEvent.js
$.Redactor.prototype.WoltLabEvent=function(){"use strict";return{init:function(){this._callbacks=[],this._elementId=this.$element[0].id,require(["EventHandler"],this.WoltLabEvent._setEvents.bind(this))},_setEvents:function(t){var e=this.$element[0].id,i=this.observe.load;this.observe.load=function(){i.call(this),t.fire("com.woltlab.wcf.redactor","observe_load_"+e,{editor:this.$editor[0]})}.bind(this),this.opts.callbacks.keyup=function(i){var n={cancel:!1,event:i};return t.fire("com.woltlab.wcf.redactor","keyup_"+e,n),n.cancel===!1},t.add("com.woltlab.wcf.redactor2","getText_"+e,function(t){t.message=this.code.get()}.bind(this))},register:function(t,e){require(["EventHandler"],function(i){-1===this._callbacks.indexOf(t)&&(this.opts.callbacks[t]=function(e){var n={cancel:!1,event:e,redactor:this};return i.fire("com.woltlab.wcf.redactor2",t+"_"+this.WoltLabEvent._elementId,n),n.cancel===!1}.bind(this),this._callbacks.push(t)),require(["EventHandler"],function(i){i.add("com.woltlab.wcf.redactor2",t+"_"+this.WoltLabEvent._elementId,e)}.bind(this))}.bind(this))}}};
// WoltLabImage.js
-$.Redactor.prototype.WoltLabImage=function(){"use strict";return{init:function(){this.opts.modal["image-edit"]='<div class="section"><dl><dt><label>'+this.lang.get("title")+'</label></dt><dd><input type="text" id="redactor-image-title" class="long"></dd></dl><dl><dt><label>'+this.lang.get("link")+'</label></dt><dd><input type="text" id="redactor-image-link" class="long" aria-label="'+this.lang.get("link")+'"></dd></dl><div class="formSubmit"><button id="redactor-modal-button-action" class="buttonPrimary">Insert</button><button id="redactor-modal-button-delete" class="redactor-modal-button-offset">Delete</button></div></div>'}}};
+$.Redactor.prototype.WoltLabImage=function(){"use strict";return{init:function(){var e=this.button.add("woltlabImage","");this.button.addCallback(e,this.WoltLabImage.add);var t=this.image.showEdit;this.image.showEdit=function(e){t(e),elById("redactor-image-source").value=e[0].src;var a=elById("redactor-image-float");e[0].classList.contains("messageFloatObjectLeft")?a.value="left":e[0].classList.contains("messageFloatObjectRight")&&(a.value="right")};var a=this.image.update;this.image.update=function(){var e=elById("redactor-image-source"),t=function(e,t){$('<small class="innerError" />').text(t).insertAfter(e)},i=e.value.trim();if(""===i)return t(e,WCF.Language.get("wcf.global.form.error.empty"));if(!i.match(this.opts.regexps.url))return t(e,WCF.Language.get("wcf.editor.image.source.error.invalid"));var r=this.observe.image[0];r.src=i,r.classList.remove("messageFloatObjectLeft"),r.classList.remove("messageFloatObjectRight");var o=elById("redactor-image-float").value;("left"===o||"right"===o)&&r.classList.add("messageFloatObject"+WCF.String.ucfirst(o)),a(),r.removeAttribute("alt"),r.removeAttribute("title")}.bind(this),this.opts.modal["image-edit"]='<div class="section"><dl><dt><label for="redactor-image-source">'+WCF.Language.get("wcf.editor.image.source")+'</label></dt><dd><input type="text" id="redactor-image-source" class="long"><small>'+WCF.Language.get("wcf.editor.image.source.description")+'</small></dd></dl><dl><dt><label for="redactor-image-link">'+WCF.Language.get("wcf.editor.image.link")+'</label></dt><dd><input type="text" id="redactor-image-link" class="long"><small>'+WCF.Language.get("wcf.editor.image.link.description")+'</small></dd></dl><dl><dt><label for="redactor-image-float">'+WCF.Language.get("wcf.editor.image.float")+'</label></dt><dd><select id="redactor-image-float"><option value="none">'+WCF.Language.get("wcf.global.noSelection")+'</option><option value="left">'+WCF.Language.get("wcf.editor.image.float.left")+'</option><option value="right">'+WCF.Language.get("wcf.editor.image.float.right")+"</option></select><small>"+WCF.Language.get("wcf.editor.image.float.description")+'</small></dd></dl><input id="redactor-image-title" style="display: none"><div class="formSubmit"><button id="redactor-modal-button-action" class="buttonPrimary">Insert</button><button id="redactor-modal-button-delete" class="redactor-modal-button-offset">Delete</button></div></div>'},add:function(){this.modal.load("image-edit",WCF.Language.get("wcf.editor.image.insert")),this.modal.show(),this.modal.getDeleteButton().hide();var e=this.modal.getActionButton();e[0].addEventListener(WCF_CLICK_EVENT,this.WoltLabImage.insert)},insert:function(e){e.preventDefault(),this.modal.getModal().find(".innerError").remove();var t=elById("redactor-image-source"),a=function(e,t){$('<small class="innerError" />').text(t).insertAfter(e)},i=t.value.trim();if(""===i)return a(t,WCF.Language.get("wcf.global.form.error.empty"));if(!i.match(this.opts.regexps.url))return a(t,WCF.Language.get("wcf.editor.image.source.error.invalid"));var r=elById("redactor-image-link"),o=r.value.trim();if(""!==o&&!o.match(this.opts.regexps.url))return a(r,WCF.Language.get("wcf.editor.image.link.error.invalid"));var l=elById("redactor-image-float").value,s="";("left"===l||"right"===l)&&(s="messageFloatObject"+WCF.String.ucfirst(l));var d='<img src="'+WCF.String.escapeHTML(i)+'"'+(s?' class="'+s+'"':"")+">";o&&(d='<a href="'+WCF.String.escapeHTML(o)+'">'+d+"</a>"),this.modal.close(),this.insert.html(d)}}};
// WoltLabLink.js
$.Redactor.prototype.WoltLabLink=function(){"use strict";var i=null;return{init:function(){this.link.show=this.WoltLabLink.show.bind(this),require(["WoltLab/WCF/Ui/Redactor/Link"],function(t){i=t})},show:function(t){"undefined"!=typeof t&&t.preventDefault&&t.preventDefault(),this.observe.closeAllTooltip();var e=this.link.is();i.showDialog({insert:e===!1,submitCallback:function(){var i=this.link.buildLinkFromModal();return i===!1?!1:(this.selection.restore(),this.link.insert(i,!0),!0)}.bind(this)});var n=this.link.buildLinkFromElement(e);n.url=this.link.removeSelfHostFromUrl(n.url),this.link.setModalValues(n),this.detect.isDesktop()&&$("#redactor-link-url").focus()}}};
// WoltLabMedia.js