// WoltLabBlock.js
$.Redactor.prototype.WoltLabBlock=function(){"use strict";return{init:function(){this.block.tags=["p","blockquote","pre","h1","h2","h3","h4","h5","h6","div","figure"],this.block.format=function(t,o,i,e){return t="quote"===t?"blockquote":t,-1!==$.inArray(t,this.block.tags)?("p"===t&&"undefined"==typeof o&&(o="class"),this.placeholder.hide(),this.buffer.set(),this.utils.isCollapsed()?this.block.formatCollapsed(t,o,i,e):this.block.formatUncollapsed(t,o,i,e)):void 0}.bind(this);var t=this.block.formatCollapsed;this.block.formatCollapsed=function(o,i,e,s){for(var l=t.call(this,o,i,e,s),h=0,a=l.length;a>h;h++)this.WoltLabBlock._paragraphize(l[h]);return l}.bind(this);var o=this.block.formatUncollapsed;this.block.formatUncollapsed=function(t,i,e,s){for(var l,h=o.call(this,t,i,e,s),a=null,r=0,n=h.length;n>r;r++)if(l=h[r][0],this.WoltLabBlock._paragraphize(l),0===r)a=l;else{for(;l.childNodes.length;)a.appendChild(l.childNodes[0]);elRemove(l)}return $(a)}.bind(this)},register:function(t,o){-1===this.block.tags.indexOf(t)&&(this.block.tags.push(t),this.opts.paragraphizeBlocks.push(t),-1===this.opts.blockTags.indexOf(t)&&(this.opts.blockTags.push(t),this.reIsBlock=new RegExp("^("+this.opts.blockTags.join("|").toUpperCase()+")$","i")),o&&this.WoltLabKeydown.register(t))},_paragraphize:function(t){if(-1===["p","pre","h1","h2","h3","h4","h5","h6","div","figure"].indexOf(t.nodeName.toLowerCase())){for(var o=elCreate("p");t.childNodes.length;)o.appendChild(t.childNodes[0]);t.appendChild(o)}}}};
// WoltLabButton.js
-$.Redactor.prototype.WoltLabButton=function(){"use strict";return{init:function(){var t,o,s,e;for(s=0,e=this.opts.woltlab.customButtons.length;e>s;s++)o=this.opts.woltlab.customButtons[s],t=this.button.add(o,""),this.button.addCallback(t,this.WoltLabButton._handleCustomButton);var n;for(s=0,e=this.opts.buttons.length;e>s;s++)if(o=this.opts.buttons[s],"wcfSeparator"!==o){if(!this.opts.woltlab.buttons.hasOwnProperty(o))throw new Error("Missing button definition for '"+o+"'.");switch(n=this.opts.woltlab.buttons[o],o){case"subscript":case"superscript":t=this.button.addAfter(this.opts.buttons[s-1],o,""),this.button.setEvent(t,o,{func:"inline.format"});break;case"redo":case"undo":t=this.button.addAfter(this.opts.buttons[s-1],o,""),this.button.addCallback(t,this.buffer[o]);break;default:t=this.button.get(o)}if(this.button.setIcon(t,'<span class="icon icon16 '+n.icon+'"></span>'),!t[0])throw new Error("Missing button element for '"+o+"'.");elAttr(t[0],"title",n.title),t[0].classList.add("jsTooltip")}for(var i,r={},l=[],a=this.core.toolbar()[0];a.childElementCount;)i=a.removeChild(a.children[0]),o=elAttr(i.children[0],"rel"),r[o]=i,l.push(o);var h=!1;for(s=0,e=this.opts.buttons.length;e>s;s++)o=this.opts.buttons[s],"wcfSeparator"!==o?(i=r[o],a.appendChild(i),l.splice(l.indexOf(o),1),h&&(i.classList.add("redactor-toolbar-separator"),h=!1)):h=!0;for(s=0,e=a.childElementCount;e>s;s++)i=a.children[s],t=i.children[0],elData(i,"show-on-mobile",-1!==this.opts.woltlab.buttonMobile.indexOf(t.rel));l.forEach(function(t){a.appendChild(r[t])}),WCF.DOMNodeInsertedHandler.execute()},_handleCustomButton:function(t){var o={cancel:!1};if(WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","bbcode_"+t+"_"+this.$element[0].id,o),o.cancel!==!0){this.buffer.set();var s="["+t+"]"+this.selection.html()+(this.selection.is()?"":this.marker.html())+"[/"+t+"]";this.insert.html(s),this.selection.restore()}}}};
+$.Redactor.prototype.WoltLabButton=function(){"use strict";return{init:function(){var t,s,o,e;for(o=0,e=this.opts.woltlab.customButtons.length;e>o;o++)s=this.opts.woltlab.customButtons[o],t=this.button.add(s,""),this.button.addCallback(t,this.WoltLabButton._handleCustomButton);var n;for(o=0,e=this.opts.buttons.length;e>o;o++)if(s=this.opts.buttons[o],"wcfSeparator"!==s){if(!this.opts.woltlab.buttons.hasOwnProperty(s))throw new Error("Missing button definition for '"+s+"'.");switch(n=this.opts.woltlab.buttons[s],"underline"===s&&(this.opts.activeButtonsStates.u="underline"),s){case"subscript":case"superscript":t=this.button.addAfter(this.opts.buttons[o-1],s,""),this.button.setEvent(t,s,{func:"inline.format"}),this.opts.activeButtonsStates["subscript"===s?"sub":"sup"]=s;break;case"redo":case"undo":t=this.button.addAfter(this.opts.buttons[o-1],s,""),this.button.addCallback(t,this.buffer[s]);break;default:t=this.button.get(s)}if(this.button.setIcon(t,'<span class="icon icon16 '+n.icon+'"></span>'),!t[0])throw new Error("Missing button element for '"+s+"'.");elAttr(t[0],"title",n.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 h=!1;for(o=0,e=this.opts.buttons.length;e>o;o++)s=this.opts.buttons[o],"wcfSeparator"!==s?(i=r[s],l.appendChild(i),a.splice(a.indexOf(s),1),h&&(i.classList.add("redactor-toolbar-separator"),h=!1)):h=!0;for(o=0,e=l.childElementCount;e>o;o++)i=l.children[o],t=i.children[0],elData(i,"show-on-mobile",-1!==this.opts.woltlab.buttonMobile.indexOf(t.rel));a.forEach(function(t){l.appendChild(r[t])}),WCF.DOMNodeInsertedHandler.execute()},_handleCustomButton:function(t){var s={cancel:!1};if(WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","bbcode_"+t+"_"+this.$element[0].id,s),s.cancel!==!0){this.buffer.set();var o="["+t+"]"+this.selection.html()+(this.selection.is()?"":this.marker.html())+"[/"+t+"]";this.insert.html(o),this.selection.restore()}}}};
// WoltLabCaret.js
$.Redactor.prototype.WoltLabCaret=function(){"use strict";return{init:function(){var t=this.caret.after;this.caret.after=function(e){e=this.caret.prepare(e),this.utils.isBlockTag(e.tagName)&&this.WoltLabCaret._addParagraphAfterBlock(e),t.call(this,e)}.bind(this),this.$editor[0].addEventListener("mouseup",this.WoltLabCaret._handleEditorClick.bind(this)),this.WoltLabCaret._initInternalRange()},endOfEditor:function(){var t=this.core.editor()[0];document.activeElement!==t&&t.focus();var e=t.lastElementChild;"P"===e.nodeName?this.caret.end(e):this.caret.after(e)},_initInternalRange:function(){var t=this.core.editor()[0],e=null,i=window.getSelection(),n=function(){e=i.rangeCount?i.getRangeAt(0).cloneRange():null},r=function(){if(null!==e){if(document.activeElement===t){var n=i.getRangeAt(0);if(0!==n.startOffset)return;for(var r=n.startContainer;r;){if(r.parentNode===t){if(r.previousSibling)return;break}if(r.previousSibling)return;r=r.parentNode}if(!r)return}t.focus(),i.removeAllRanges(),i.addRange(e),e=null}};this.$editor[0].addEventListener("keyup",n),this.$editor[0].addEventListener("mouseup",function(){i.rangeCount&&n()});var a=this.selection.save;this.selection.save=function(){e=null,a.call(this)}.bind(this);var o=this.selection.restore;this.selection.restore=function(){e&&(r(),i.rangeCount&&this.utils.isRedactorParent(i.getRangeAt(0).commonAncestorContainer))||o.call(this)}.bind(this);var s=this.buffer.set;this.buffer.set=function(e){document.activeElement!==t&&r(),s.call(this,e),n()}.bind(this);var l=this.insert.html;this.insert.html=function(t,e){l.call(this,t,e),n()}.bind(this)},_handleEditorClick:function(t){if(t.target===this.$editor[0]&&this.selection.get().isCollapsed){var e=this.selection.block();if(e!==!1&&("P"!==e.nodeName||(e=e.parentNode,e!==this.$editor[0]&&this.utils.isBlockTag(e.nodeName)))){if("TD"===e.nodeName)for(;"TABLE"!==e.nodeName;)e=e.parentNode;this.buffer.set();var i=t.clientY<e.getBoundingClientRect().top,n=elCreate("p");n.textContent="",e.parentNode.insertBefore(n,i?e:e.nextSibling),this.caret.end(n)}}},_addParagraphAfterBlock:function(t){var e=t.nextElementSibling;(!e||"P"!==e.nodeName&&!this.utils.isBlockTag(e.nodeName))&&(e=elCreate("p"),e.textContent="",t.parentNode.insertBefore(e,t.nextSibling))}}};
// WoltLabClean.js