(function (window, undefined) { $.Redactor.prototype.WoltLabButton=function(){"use strict";var t;return{init:function(){var t,e,o,n,s,i,a,r,l,d,c,u,h,b;for(o=0,n=this.opts.woltlab.customButtons.length;o<n;o++)e=this.opts.woltlab.customButtons[o],t=this.button.add(e,""),this.button.addCallback(t,this.WoltLabButton._handleCustomButton);for(s=this.core.toolbar()[0],o=0,n=this.opts.buttons.length;o<n;o++)if("wcfSeparator"!==(e=this.opts.buttons[o])){if(!this.opts.woltlab.buttons.hasOwnProperty(e))throw new Error("Missing button definition for '"+e+"'.");switch(i=this.opts.woltlab.buttons[e],"underline"===e&&(this.opts.activeButtonsStates.u="underline"),e){case"subscript":case"superscript":t=this.button.addAfter(this.opts.buttons[o-1],e,""),this.button.setEvent(t,e,{func:"inline.format"}),this.opts.activeButtonsStates["subscript"===e?"sub":"sup"]=e;break;case"redo":case"undo":t=this.button.addAfter(this.opts.buttons[o-1],e,""),this.button.addCallback(t,this.buffer[e]);break;default:t=this.button.get(e)}if(r=!(a=i.icon).match(/^fa-/)&&a.match(/\.(gif|jpe?g|png|svg)$/),this.button.setIcon(t,'<span class="icon icon16 '+(r?"redactorButtonImage":a)+'"'+(r?" style=\"background-image: url('"+WCF_PATH+"icon/"+a+"')\"":"")+"></span>"),!t[0])throw new Error("Missing button element for '"+e+"'.");t[0].title=i.title,t[0].classList.add("jsTooltip"),"lists"===e&&(l=t.data("dropdown"),elBySel(".redactor-dropdown-outdent span",l[0]).textContent=WCF.Language.get("wcf.editor.list.outdent"),elBySel(".redactor-dropdown-indent span",l[0]).textContent=WCF.Language.get("wcf.editor.list.indent"))}for(d=this.opts.buttons.indexOf("tt"),-1!==this.opts.buttons.indexOf("code")&&-1!==d&&(this.opts.buttons.splice(d,1),this.opts.buttons.splice(this.opts.buttons.indexOf("code")+1,0,"tt")),u={},h=[];s.childElementCount;)c=s.removeChild(s.children[0]),e=elAttr(c.children[0],"rel"),u[e]=c,h.push(e);for(b=!1,o=0,n=this.opts.buttons.length;o<n;o++)"wcfSeparator"!==(e=this.opts.buttons[o])?(c=u[e],s.appendChild(c),h.splice(h.indexOf(e),1),b&&(c.classList.add("redactor-toolbar-separator"),b=!1)):b=!0;for(o=0,n=s.childElementCount;o<n;o++)t=(c=s.children[o]).children[0],elData(c,"show-on-mobile",-1!==this.opts.woltlab.buttonMobile.indexOf(t.rel));h.forEach((function(t){s.appendChild(u[t])})),WCF.DOMNodeInsertedHandler.execute(),require(["Ui/Screen"],function(t){t.on("screen-xs",{match:this.WoltLabButton._enableToggleButton.bind(this),unmatch:this.WoltLabButton._disableToggleButton.bind(this),setup:this.WoltLabButton._setupToggleButton.bind(this)})}.bind(this)),s.addEventListener("dragstart",(function(t){t.preventDefault()})),elAttr(elBySel(".re-html",s),"tabindex",0)},_handleCustomButton:function(t){var e,o,n={cancel:!1};if(WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","bbcode_"+t+"_"+this.$element[0].id,n),!0!==n.cancel){const n=this.selection.block();if(n&&"PRE"===n.nodeName)return;this.buffer.set(),(e=this.marker.get()).classList.add("woltlab-bbcode-marker"),o="["+t+"]"+this.selection.html()+e.outerHTML+"[/"+t+"]",this.insert.html(o),this.selection.restore()}window.setTimeout(function(){document.activeElement!==this.$editor[0]&&this.$editor[0].focus()}.bind(this),10)},_enableToggleButton:function(){null===t.parentNode&&this.$toolbar[0].appendChild(t)},_disableToggleButton:function(){t&&null!==t.parentNode&&this.$toolbar[0].removeChild(t)},_setupToggleButton:function(){var e,o;(t=elCreate("li")).className="redactorToolbarToggle",t.innerHTML='<a href="#"><span class="icon icon16 fa-caret-down"></span></a>',elData(t,"show-on-mobile",!0),e=t.children[0].children[0],o=function(t){t instanceof Event&&t.preventDefault(),this.$toolbar[0].classList.toggle("redactorToolbarOverride")&&document.activeElement&&document.activeElement!==this.$editor[0]&&document.activeElement.blur(),e.classList.toggle("fa-caret-down"),e.classList.toggle("fa-caret-up")}.bind(this),t.children[0].addEventListener("mousedown",o),this.$toolbar[0].appendChild(t),WCF.System.Event.addListener("com.woltlab.wcf.redactor2","reset_"+this.$element[0].id,function(){this.$toolbar[0].classList.contains("redactorToolbarOverride")&&o()}.bind(this))}}}; })(this);
// plugins/WoltLabCaret.js
-(function (window, undefined) { $.Redactor.prototype.WoltLabCaret=function(){"use strict";var e,t=!1,n=!1;return{init:function(){var i,o,r,a,s,l,d=this.caret.after;this.caret.after=function(e){e=this.caret.prepare(e),this.utils.isBlockTag(e.tagName)&&this.WoltLabCaret._addParagraphAfterBlock(e),d.call(this,e)}.bind(this),i=this.caret.start,this.caret.start=function(e){if(n){if(!(e=this.caret.prepare(e)))return;"P"===e.nodeName&&""===e.innerHTML&&(e.innerHTML="<br>")}i.call(this,e)}.bind(this),o=this.core.editor()[0],require(["Environment"],function(i){var r,a;t="ios"===i.platform(),(n="safari"===i.browser())&&o.classList.add("jsSafariMarginClickTarget"),r=this.WoltLabCaret._handleEditorClick.bind(this),a=this.WoltLabCaret._handleEditorMouseUp.bind(this),n&&t?(o.addEventListener("touchstart",(function(t){e=t.target}),{passive:!0}),o.addEventListener("touchend",function(e){r(e),a(e)}.bind(this))):(o.addEventListener("click",function(e){this.WoltLabCaret._detectTripleClick(e),r(e)}.bind(this)),o.addEventListener("mouseup",a))}.bind(this)),r=this.caret.end,this.caret.end=function(e){var n,i,o,a;return"OL"!==(e=this.caret.prepare(e)).nodeName&&"UL"!==e.nodeName||null===(e=e.lastElementChild)&&(e=e.parentNode),n=!1,e.nodeType===Node.ELEMENT_NODE&&e.lastChild&&"P"===e.lastChild.nodeName?n=!0:t?(i=this.core.editor()[0],e.parentNode===i&&"<p><br></p>"===i.innerHTML&&(n=!0)):"P"===e.nodeName&&0===e.childNodes.length&&(e.innerHTML="",n=!0),n?(o=window.getSelection(),(a=document.createRange()).selectNodeContents(e.lastChild),a.collapse(!1),o.removeAllRanges(),void o.addRange(a)):"P"===e.nodeName&&1===e.childNodes.length&&"BR"===e.childNodes[0].nodeName?this.caret.before(e.childNodes[0]):r.call(this,e)}.bind(this),a=this.selection.nodes,this.selection.nodes=function(e){var t,n=a.call(this,e);return 1===n.length&&n[0]===this.$editor[0]&&(t=this.selection.range(this.selection.get())).startContainer===t.endContainer?[t.startContainer]:n}.bind(this),this.WoltLabCaret._initInternalRange(),s=this.selection.saveInstant,this.selection.saveInstant=function(){var e,t,n=s.call(this);return n&&(n.isAtNodeStart=!1,(e=window.getSelection()).rangeCount&&!e.isCollapsed&&(t=e.getRangeAt(0)).startContainer.nodeType===Node.TEXT_NODE&&0===t.startOffset&&(n.isAtNodeStart=!0)),n}.bind(this),l=this.selection.restoreInstant,this.selection.restoreInstant=function(e){var t,n,i,o,r,a,s,d;if((void 0!==e||this.saved)&&(t=void 0!==e?e:this.saved,l.call(this,e),(n=window.getSelection()).rangeCount))if(!0===t.isAtNodeStart){if(!n.isCollapsed){if(o=(i=n.getRangeAt(0)).startContainer,t.node===o)return;for(;null!==o&&"P"!==o.nodeName;)o=o.parentNode;if(null!==o&&null!==(o=o.nextElementSibling)&&"P"===o.nodeName&&0===o.textContent.replace(/\u200B/g,"").length){for(o=o.nextElementSibling,r=t.node;null!==r&&r!==o;)r=r.parentNode;r===o&&((i=i.cloneRange()).setStart(t.node,0),n.removeAllRanges(),n.addRange(i))}}}else n.isCollapsed&&(a=n.anchorNode,s=this.core.editor()[0],a.nodeType===Node.TEXT_NODE&&a.parentNode===s&&n.anchorOffset===a.textContent.length&&(d=a.nextElementSibling)&&"P"===d.nodeName&&this.caret.start(d))}.bind(this),this.selection.nodes=function(e){var t,n,i,o=void 0===e?[]:$.isArray(e)?e:[e],r=this.selection.get(),a=this.selection.range(r),s=[],l=[];if(this.utils.isCollapsed())s=[this.selection.current()];else{if((t=a.startContainer)===(n=a.endContainer))return[t];for(i=a.commonAncestorContainer;t&&t!==n;)s.push(t=this.selection.nextNode(t,i));for(t=a.startContainer;t&&t!==i;)s.unshift(t),t=t.parentNode}return $.each(s,(function(e,t){if(t){var n=1===t.nodeType&&t.tagName.toLowerCase();if($(t).hasClass("redactor-script-tag")||$(t).hasClass("redactor-selection-marker"))return;if(n&&0!==o.length&&-1===$.inArray(n,o))return;l.push(t)}})),0===l.length?[]:l}.bind(this),this.selection.nextNode=function(e,t){if(e.hasChildNodes())return e.firstChild;for(;e&&!e.nextSibling;)if(e=e.parentNode,t&&e===t)return null;return e?e.nextSibling:null}},paragraphAfterBlock:function(e){var t=e.nextElementSibling;t&&"P"!==t.nodeName&&(t=elCreate("p"),"<p><br></p>"===this.opts.emptyHtml?t.innerHTML="<br>":t.textContent="",e.parentNode.insertBefore(t,e.nextSibling)),this.caret.after(e)},endOfEditor:function(){var e,t=this.core.editor()[0];document.activeElement!==t&&t.focus(),"P"===(e=t.lastElementChild).nodeName?this.caret.end(e):this.caret.after(e)},_initInternalRange:function(){var e,t,n,i,o,r=this.core.editor()[0],a=null,s=window.getSelection(),l=function(){a=s.rangeCount?s.getRangeAt(0).cloneRange():null};this.WoltLabCaret.forceSelectionSave=l,e=function(){var e,t,n,i;if(null!==a){if(document.activeElement===r){if(0!==(e=s.getRangeAt(0)).startOffset)return;for(t=e.startContainer;t;){if(t.parentNode===r){if(t.previousSibling)return;break}if(t.previousSibling)return;t=t.parentNode}if(!t)return}n=r.scrollLeft,i=r.scrollTop,r.focus(),r.scrollLeft=n,r.scrollTop=i,s.removeAllRanges(),s.addRange(a),a=null}},r.addEventListener("keyup",l),r.addEventListener("mouseup",(function(){s.rangeCount&&l()})),t=this.selection.save,this.selection.save=function(){a=null,t.call(this)}.bind(this),n=this.selection.restore,this.selection.restore=function(){a&&null===elBySel(".redactor-selection-marker",this.$editor[0])&&(e(),s.rangeCount&&this.utils.isRedactorParent(s.getRangeAt(0).commonAncestorContainer))||n.call(this)}.bind(this),i=this.buffer.set,this.buffer.set=function(t){if(document.activeElement!==r){var n=window.getSelection();n.rangeCount&&!1!==this.utils.isRedactorParent(n.anchorNode)?r.focus():e()}i.call(this,t),l()}.bind(this),o=this.insert.html,this.insert.html=function(e,t){var n=elBySel(".redactor-selection-marker",this.$editor[0]);o.call(this,e,t),(n||null===elBySel(".redactor-selection-marker",this.$editor[0]))&&l()}.bind(this),require(["Environment"],function(e){"ios"===e.platform()&&(r.addEventListener("focus",(function(){document.addEventListener("selectionchange",l)})),r.addEventListener("blur",(function(){document.removeEventListener("selectionchange",l)})))}.bind(this))},_detectTripleClick:function(e){var t,n,i;e.detail<3||(t=window.getSelection()).isCollapsed||"TR"===(n=t.getRangeAt(0)).commonAncestorContainer.nodeName&&(i=elClosest(n.startContainer,"td"),(n=document.createRange()).selectNodeContents(i),t.removeAllRanges(),t.addRange(n))},_handleEditorClick:function(i){var o,r,a,s,l,d,c,h,u,f,g,N=this.selection.get();if((!N.anchorNode||this.core.editor()[0].contains(N.anchorNode))&&(o=i.clientY,r=t&&e===i.target&&this.utils.isBlockTag(e.nodeName),void 0===o&&r&&(o=i.changedTouches[0].clientY),(this.selection.get().isCollapsed||r&&void 0!==o)&&(!1!==(a=this.selection.block())||(this.selection.current()===this.$editor[0]&&(s=this.$editor[0].childNodes[this.selection.get().anchorOffset])&&s.nodeType===Node.ELEMENT_NODE&&"TABLE"===s.nodeName&&(a=s),!1!==a)))){for(l=!1,n&&this.utils.isBlockTag(i.target.nodeName)&&o>i.target.getBoundingClientRect().bottom&&(a=i.target,l=!0),d=i.target;d&&!this.utils.isBlockTag(d.nodeName);)d=d.parentNode;if(d&&(l||d!==a)&&("P"!==a.nodeName||(a=a.parentNode)!==this.$editor[0]&&this.utils.isBlockTag(a.nodeName))){if("TD"===a.nodeName)for(;"TABLE"!==a.nodeName;)a=a.parentNode;if(!a.nodeName.match(/^H\d$/)&&!$(a).closest("ol, ul",this.$editor[0]).length){for(u=a;u;){if(o<(h=u.getBoundingClientRect()).top)c=!0,a=u;else{if(!(o>h.bottom))break;c=!1,a=u}if(!u.parentNode||u.parentNode===this.$editor[0])break;u=u.parentNode}void 0!==c&&((f=a[(c?"previous":"next")+"ElementSibling"])&&"P"===f.nodeName?this.caret.end(f):(this.buffer.set(),(g=elCreate("p")).textContent="",a.parentNode.insertBefore(g,c?a:a.nextSibling),this.caret.end(g)))}}}},_handleEditorMouseUp:function(i){var o,r,a,s,l,d=window.getSelection();if(d.rangeCount&&(d.isCollapsed||n&&t&&e===i.target&&this.utils.isBlockTag(e.nodeName)))if(i.target===this.$editor[0])(o=d.anchorNode).nodeType===Node.TEXT_NODE&&(o=o.parentNode),"KBD"===o.nodeName&&(null!==(r=o.previousSibling)&&""===r.textContent||(r=document.createTextNode(""),o.parentNode.insertBefore(r,o)),this.caret.before(r));else if("KBD"===i.target.nodeName&&(a=i.target,(o=d.anchorNode).nodeType===Node.TEXT_NODE)){for(r=o;(r=r.nextSibling)&&r.nodeType===Node.TEXT_NODE&&(""===r.textContent||""===r.textContent););r===a&&(0!==a.childNodes.length&&""===a.childNodes[0].textContent||(s=document.createTextNode(""),a.insertBefore(s,a.firstChild)),(l=document.createRange()).setStartAfter(a.childNodes[0]),l.setEndAfter(a.childNodes[0]),d.removeAllRanges(),d.addRange(l))}},_addParagraphAfterBlock:function(e){var t=e.nextElementSibling;t&&("P"===t.nodeName||this.utils.isBlockTag(t.nodeName))||((t=elCreate("p")).textContent="",e.parentNode.insertBefore(t,e.nextSibling))}}}; })(this);
+(function (window, undefined) { $.Redactor.prototype.WoltLabCaret=function(){"use strict";var e,t=!1,n=!1;return{init:function(){var i,o,r,a,s,l,d=this.caret.after;this.caret.after=function(e){e=this.caret.prepare(e),this.utils.isBlockTag(e.tagName)&&this.WoltLabCaret._addParagraphAfterBlock(e),d.call(this,e)}.bind(this),i=this.caret.start,this.caret.start=function(e){if(n){if(!(e=this.caret.prepare(e)))return;"P"===e.nodeName&&""===e.innerHTML&&(e.innerHTML="<br>")}i.call(this,e)}.bind(this),o=this.core.editor()[0],require(["Environment"],function(i){var r,a;t="ios"===i.platform(),(n="safari"===i.browser())&&o.classList.add("jsSafariMarginClickTarget"),r=this.WoltLabCaret._handleEditorClick.bind(this),a=this.WoltLabCaret._handleEditorMouseUp.bind(this),n&&t?(o.addEventListener("touchstart",(function(t){e=t.target}),{passive:!0}),o.addEventListener("touchend",function(e){const t=window.getSelection();(0===t.rangeCount||t.isCollapsed)&&(r(e),a(e))}.bind(this))):(o.addEventListener("click",function(e){this.WoltLabCaret._detectTripleClick(e),r(e)}.bind(this)),o.addEventListener("mouseup",a))}.bind(this)),r=this.caret.end,this.caret.end=function(e){var n,i,o,a;return"OL"!==(e=this.caret.prepare(e)).nodeName&&"UL"!==e.nodeName||null===(e=e.lastElementChild)&&(e=e.parentNode),n=!1,e.nodeType===Node.ELEMENT_NODE&&e.lastChild&&"P"===e.lastChild.nodeName?n=!0:t?(i=this.core.editor()[0],e.parentNode===i&&"<p><br></p>"===i.innerHTML&&(n=!0)):"P"===e.nodeName&&0===e.childNodes.length&&(e.innerHTML="",n=!0),n?(o=window.getSelection(),(a=document.createRange()).selectNodeContents(e.lastChild),a.collapse(!1),o.removeAllRanges(),void o.addRange(a)):"P"===e.nodeName&&1===e.childNodes.length&&"BR"===e.childNodes[0].nodeName?this.caret.before(e.childNodes[0]):r.call(this,e)}.bind(this),a=this.selection.nodes,this.selection.nodes=function(e){var t,n=a.call(this,e);return 1===n.length&&n[0]===this.$editor[0]&&(t=this.selection.range(this.selection.get())).startContainer===t.endContainer?[t.startContainer]:n}.bind(this),this.WoltLabCaret._initInternalRange(),s=this.selection.saveInstant,this.selection.saveInstant=function(){var e,t,n=s.call(this);return n&&(n.isAtNodeStart=!1,(e=window.getSelection()).rangeCount&&!e.isCollapsed&&(t=e.getRangeAt(0)).startContainer.nodeType===Node.TEXT_NODE&&0===t.startOffset&&(n.isAtNodeStart=!0)),n}.bind(this),l=this.selection.restoreInstant,this.selection.restoreInstant=function(e){var t,n,i,o,r,a,s,d;if((void 0!==e||this.saved)&&(t=void 0!==e?e:this.saved,l.call(this,e),(n=window.getSelection()).rangeCount))if(!0===t.isAtNodeStart){if(!n.isCollapsed){if(o=(i=n.getRangeAt(0)).startContainer,t.node===o)return;for(;null!==o&&"P"!==o.nodeName;)o=o.parentNode;if(null!==o&&null!==(o=o.nextElementSibling)&&"P"===o.nodeName&&0===o.textContent.replace(/\u200B/g,"").length){for(o=o.nextElementSibling,r=t.node;null!==r&&r!==o;)r=r.parentNode;r===o&&((i=i.cloneRange()).setStart(t.node,0),n.removeAllRanges(),n.addRange(i))}}}else n.isCollapsed&&(a=n.anchorNode,s=this.core.editor()[0],a.nodeType===Node.TEXT_NODE&&a.parentNode===s&&n.anchorOffset===a.textContent.length&&(d=a.nextElementSibling)&&"P"===d.nodeName&&this.caret.start(d))}.bind(this),this.selection.nodes=function(e){var t,n,i,o=void 0===e?[]:$.isArray(e)?e:[e],r=this.selection.get(),a=this.selection.range(r),s=[],l=[];if(this.utils.isCollapsed())s=[this.selection.current()];else{if((t=a.startContainer)===(n=a.endContainer))return[t];for(i=a.commonAncestorContainer;t&&t!==n;)s.push(t=this.selection.nextNode(t,i));for(t=a.startContainer;t&&t!==i;)s.unshift(t),t=t.parentNode}return $.each(s,(function(e,t){if(t){var n=1===t.nodeType&&t.tagName.toLowerCase();if($(t).hasClass("redactor-script-tag")||$(t).hasClass("redactor-selection-marker"))return;if(n&&0!==o.length&&-1===$.inArray(n,o))return;l.push(t)}})),0===l.length?[]:l}.bind(this),this.selection.nextNode=function(e,t){if(e.hasChildNodes())return e.firstChild;for(;e&&!e.nextSibling;)if(e=e.parentNode,t&&e===t)return null;return e?e.nextSibling:null}},paragraphAfterBlock:function(e){var t=e.nextElementSibling;t&&"P"!==t.nodeName&&(t=elCreate("p"),"<p><br></p>"===this.opts.emptyHtml?t.innerHTML="<br>":t.textContent="",e.parentNode.insertBefore(t,e.nextSibling)),this.caret.after(e)},endOfEditor:function(){var e,t=this.core.editor()[0];document.activeElement!==t&&t.focus(),"P"===(e=t.lastElementChild).nodeName?this.caret.end(e):this.caret.after(e)},_initInternalRange:function(){var e,t,n,i,o,r=this.core.editor()[0],a=null,s=window.getSelection(),l=function(){a=s.rangeCount?s.getRangeAt(0).cloneRange():null};this.WoltLabCaret.forceSelectionSave=l,e=function(){var e,t,n,i;if(null!==a){if(document.activeElement===r){if(0!==(e=s.getRangeAt(0)).startOffset)return;for(t=e.startContainer;t;){if(t.parentNode===r){if(t.previousSibling)return;break}if(t.previousSibling)return;t=t.parentNode}if(!t)return}n=r.scrollLeft,i=r.scrollTop,r.focus(),r.scrollLeft=n,r.scrollTop=i,s.removeAllRanges(),s.addRange(a),a=null}},r.addEventListener("keyup",l),r.addEventListener("mouseup",(function(){s.rangeCount&&l()})),t=this.selection.save,this.selection.save=function(){a=null,t.call(this)}.bind(this),n=this.selection.restore,this.selection.restore=function(){a&&null===elBySel(".redactor-selection-marker",this.$editor[0])&&(e(),s.rangeCount&&this.utils.isRedactorParent(s.getRangeAt(0).commonAncestorContainer))||n.call(this)}.bind(this),i=this.buffer.set,this.buffer.set=function(t){if(document.activeElement!==r){var n=window.getSelection();n.rangeCount&&!1!==this.utils.isRedactorParent(n.anchorNode)?r.focus():e()}i.call(this,t),l()}.bind(this),o=this.insert.html,this.insert.html=function(e,t){var n=elBySel(".redactor-selection-marker",this.$editor[0]);o.call(this,e,t),(n||null===elBySel(".redactor-selection-marker",this.$editor[0]))&&l()}.bind(this),require(["Environment"],function(e){"ios"===e.platform()&&(r.addEventListener("focus",(function(){document.addEventListener("selectionchange",l)})),r.addEventListener("blur",(function(){document.removeEventListener("selectionchange",l)})))}.bind(this))},_detectTripleClick:function(e){var t,n,i;e.detail<3||(t=window.getSelection()).isCollapsed||"TR"===(n=t.getRangeAt(0)).commonAncestorContainer.nodeName&&(i=elClosest(n.startContainer,"td"),(n=document.createRange()).selectNodeContents(i),t.removeAllRanges(),t.addRange(n))},_handleEditorClick:function(i){var o,r,a,s,l,d,c,h,u,f,g,N=this.selection.get();if((!N.anchorNode||this.core.editor()[0].contains(N.anchorNode))&&(o=i.clientY,r=t&&e===i.target&&this.utils.isBlockTag(e.nodeName),void 0===o&&r&&(o=i.changedTouches[0].clientY),(this.selection.get().isCollapsed||r&&void 0!==o)&&(!1!==(a=this.selection.block())||(this.selection.current()===this.$editor[0]&&(s=this.$editor[0].childNodes[this.selection.get().anchorOffset])&&s.nodeType===Node.ELEMENT_NODE&&"TABLE"===s.nodeName&&(a=s),!1!==a)))){for(l=!1,n&&this.utils.isBlockTag(i.target.nodeName)&&o>i.target.getBoundingClientRect().bottom&&(a=i.target,l=!0),d=i.target;d&&!this.utils.isBlockTag(d.nodeName);)d=d.parentNode;if(d&&(l||d!==a)&&("P"!==a.nodeName||(a=a.parentNode)!==this.$editor[0]&&this.utils.isBlockTag(a.nodeName))){if("TD"===a.nodeName)for(;"TABLE"!==a.nodeName;)a=a.parentNode;if(!a.nodeName.match(/^H\d$/)&&!$(a).closest("ol, ul",this.$editor[0]).length){for(u=a;u;){if(o<(h=u.getBoundingClientRect()).top)c=!0,a=u;else{if(!(o>h.bottom))break;c=!1,a=u}if(!u.parentNode||u.parentNode===this.$editor[0])break;u=u.parentNode}void 0!==c&&((f=a[(c?"previous":"next")+"ElementSibling"])&&"P"===f.nodeName?this.caret.end(f):(this.buffer.set(),(g=elCreate("p")).textContent="",a.parentNode.insertBefore(g,c?a:a.nextSibling),this.caret.end(g)))}}}},_handleEditorMouseUp:function(i){var o,r,a,s,l,d=window.getSelection();if(d.rangeCount&&(d.isCollapsed||n&&t&&e===i.target&&this.utils.isBlockTag(e.nodeName)))if(i.target===this.$editor[0])(o=d.anchorNode).nodeType===Node.TEXT_NODE&&(o=o.parentNode),"KBD"===o.nodeName&&(null!==(r=o.previousSibling)&&""===r.textContent||(r=document.createTextNode(""),o.parentNode.insertBefore(r,o)),this.caret.before(r));else if("KBD"===i.target.nodeName&&(a=i.target,(o=d.anchorNode).nodeType===Node.TEXT_NODE)){for(r=o;(r=r.nextSibling)&&r.nodeType===Node.TEXT_NODE&&(""===r.textContent||""===r.textContent););r===a&&(0!==a.childNodes.length&&""===a.childNodes[0].textContent||(s=document.createTextNode(""),a.insertBefore(s,a.firstChild)),(l=document.createRange()).setStartAfter(a.childNodes[0]),l.setEndAfter(a.childNodes[0]),d.removeAllRanges(),d.addRange(l))}},_addParagraphAfterBlock:function(e){var t=e.nextElementSibling;t&&("P"===t.nodeName||this.utils.isBlockTag(t.nodeName))||((t=elCreate("p")).textContent="",e.parentNode.insertBefore(t,e.nextSibling))}}}; })(this);
// plugins/WoltLabClean.js
(function (window, undefined) { $.Redactor.prototype.WoltLabClean=function(){"use strict";return{init:function(){var e,t,n,l,r,i,o,a,s=this.clean.onSet;this.clean.onSet=function(e){e=(e=(e=e.replace(/\u200B/g,"")).replace(/&amp;/g,"@@@WCF_LITERAL_AMP@@@")).replace(/&/g,"&WCF_AMPERSAND&"),e=(e=(e=s.call(this,e)).replace(/&WCF_AMPERSAND&(amp;)?/g,"&")).replace(/@@@WCF_LITERAL_AMP@@@/g,"&amp;");var t=elCreate("div");return t.innerHTML=e,elBySelAll("*",t,(function(e){var t,n,l,r=[];for(n=0,l=e.attributes.length;n<l;n++)0===(t=e.attributes[n]).name.indexOf("on")&&r.push(t.name);r.forEach(e.removeAttribute.bind(e))})),elBySelAll("iframe",t,elRemove),elBySelAll("pre",t,(function(e){e.classList.contains("redactor-script-tag")&&elRemove(e)})),elBySelAll("td",t,(function(e){0===e.childNodes.length&&(e.innerHTML="")})),elBySelAll("pre, woltlab-quote, woltlab-spoiler",t,(function(e){0!==e.childElementCount||0!==e.textContent.length&&!e.textContent.match(/^\r?\n$/)||(e.textContent="")})),e=t.innerHTML}.bind(this),e=this.clean.onSync,this.clean.onSync=function(t){var n,l=elCreate("div");return l.innerHTML=t,n={},elBySelAll("pre",l,(function(e){var t=WCF.getUUID();n[t]=e.textContent,e.textContent=t})),elBySelAll("p",l,(function(e){var t,n=e.lastElementChild;n&&"BR"===n.nodeName&&(n.nextSibling?n.nextSibling.textContent.replace(/[\r\n\t]/g,"").match(/^\u200B+$/)&&((t=elCreate("p")).innerHTML="<br>",e.parentNode.insertBefore(t,e.nextSibling),e.removeChild(n.nextSibling),e.removeChild(n)):(n.previousElementSibling||n.previousSibling&&""!==n.previousSibling.textContent.replace(/\u200B/g,"").trim())&&e.removeChild(n))})),elBySelAll("span",l,(function(e){if(e.childNodes.length>0){var t=e.childNodes[e.childNodes.length-1];t.nodeType===Node.TEXT_NODE&&t.textContent.match(/\n$/)&&(t.textContent=t.textContent.replace(/\n+$/,e.parentNode.lastChild===e?"":" "))}})),t=(t=(t=l.innerHTML).replace(/<p>\u200B<\/p>/g,"<p><br></p>")).replace(/&/g,"&WCF_AMPERSAND&"),t=(t=e.call(this,t)).replace(/&WCF_AMPERSAND&/g,"&"),l.innerHTML=t,elBySelAll("pre",l,(function(e){n.hasOwnProperty(e.textContent)&&(e.textContent=n[e.textContent])})),t=l.innerHTML}.bind(this),t=this.clean.savePreFormatting,this.clean.savePreFormatting=function(e){var n=this.clean.encodeEntities;return this.clean.encodeEntities=function(e){return WCF.String.escapeHTML(e)},e=t.call(this,e),this.clean.encodeEntities=n,e}.bind(this),n=this.clean.onPaste,this.clean.onPaste=function(e,t,l){var r,i,o,a,s,c,h,d,p,u,f,m,g,y,b,v;if(t.pre||this.utils.isCurrentOrParent("kbd"))return t.pre&&this.opts.preSpaces&&(e=e.replace(/\t/g,new Array(this.opts.preSpaces+1).join(" "))),WCF.String.escapeHTML(e);for(this.clean.isHtmlMsWord(e)&&(e=this.clean.cleanMsWord(e)),(r=elCreate("div")).innerHTML=e.replace(/@@@WOLTLAB-P-ALIGN-(?:left|right|center|justify)@@@/g,""),s=!0,o=0,a=r.childElementCount;o<a;o++){if("DIV"!==(i=r.children[o]).nodeName||0===i.childNodes.length){s=!1;break}if(1===i.childNodes.length&&1===i.childElementCount&&0===(c=i.children[0]).childNodes.length&&"BR"!==c.nodeName){s=!1;break}}if(s){for(h=[],o=0,a=r.childElementCount;o<a;o++)h.push(r.children[o]);h.forEach((function(e){var t=elCreate("p");for(r.insertBefore(t,e);e.childNodes.length>0;)t.appendChild(e.childNodes[0]);r.removeChild(e)}))}for(d=null!==elBySel(".MsoNormal",r),o=0,a=(p=elBySelAll("[style]",r)).length;o<a;o++){for(f=[],y=0,b=(i=p[o]).style.length;y<b;y++)u=i.style[y],-1===this.opts.woltlab.allowedInlineStyles.indexOf(u)&&("font-weight"===u&&"STRONG"!==i.nodeName?("bold"!==(g=i.style.getPropertyValue(u))&&"bolder"!==g||(g=600),(g=~~g)>500&&(m=elCreate("strong"),i.parentNode.insertBefore(m,i),m.appendChild(i))):d&&"margin-bottom"===u&&"P"===i.nodeName&&(g=i.style.getPropertyValue(u)).match(/^12(?:\.0)?pt$/)&&((v=elCreate("p")).innerHTML="<br>",i.parentNode.insertBefore(v,i.nextSibling)),f.push(u));f.forEach((function(e){i.style.removeProperty(e)}))}return elBySelAll("span",r,function(e){var t,n,l,r,i;if(!e.classList.contains("redactor-selection-marker"))if(e.hasAttribute("style")&&e.style.length)for(r=((t=e.style.getPropertyValue("color"))?1:0)+((n=e.style.getPropertyValue("font-family"))?1:0)+((l=e.style.getPropertyValue("font-size"))?1:0);r>0;){if(this.opts.pastePlainText)return e.style.removeProperty("color"),e.style.removeProperty("font-family"),void e.style.removeProperty("font-size");i=elCreate("span"),t?(i.style.setProperty("color",t,""),e.style.removeProperty("color"),t="",r--):n?(i.style.setProperty("font-family",n,""),e.style.removeProperty("font-family"),n="",r--):l&&(i.style.setProperty("font-size",l,""),e.style.removeProperty("font-size"),l="",r--),e.parentNode.insertBefore(i,e),i.appendChild(e)}else{for(;e.childNodes.length;)e.parentNode.insertBefore(e.childNodes[0],e);elRemove(e)}}.bind(this)),elBySelAll("p",r,(function(e){e.classList.contains("MsoNormal")?1===e.childElementCount&&"O:P"===e.children[0].nodeName&&" "===e.textContent&&(e.innerHTML="<br>"):e.className.match(/\btext-(left|right|center|justify)\b/)&&e.insertBefore(document.createTextNode("@@@WOLTLAB-P-ALIGN-"+RegExp.$1+"@@@"),e.firstChild),e.removeAttribute("class"),e.removeAttribute("style")})),elBySelAll("img",r,(function(e){e.removeAttribute("style")})),elBySelAll("br",r,(function(e){e.parentNode.insertBefore(document.createTextNode("@@@WOLTLAB-BR-MARKER@@@"),e.nextSibling)})),elBySelAll("kbd",r,(function(e){for(e.insertBefore(document.createTextNode("[tt]"),e.firstChild),e.appendChild(document.createTextNode("[/tt]"));e.childNodes.length;)e.parentNode.insertBefore(e.childNodes[0],e);elRemove(e)})),e=(e=(e=n.call(this,r.innerHTML,t,l)).replace(/\n*@@@WOLTLAB-BR-MARKER@@@\n*/g,"<woltlab-br-marker></woltlab-br-marker>")).replace(/(<p>)?\s*@@@WOLTLAB-P-ALIGN-(left|right|center|justify)@@@/g,(function(e,t,n){return t?'<p class="text-'+n+'">':""})),r.innerHTML=e.replace(/&quot;/g,"""),elBySelAll("woltlab-br-marker",r,(function(e){var t,n,l,r,i,o,a,s=e.parentNode;if(null!==s){for(t=!1,n=s;null!==n;)"P"===n.nodeName&&(t=!0),n=n.parentNode;if(t){for((l=elCreate("p")).innerHTML="<br>",r=!1,(i=e.nextSibling)&&"WOLTLAB-BR-MARKER"===i.nodeName&&(r=!0),o=!r;e.nextSibling;)o&&0!==e.nextSibling.textContent.replace(/\u200B/g,"").trim().length&&(o=!1),l.appendChild(e.nextSibling);o||elRemove(l.firstElementChild),(a=e.previousSibling)&&"BR"===a.nodeName&&elRemove(a),s.parentNode.insertBefore(l,s.nextSibling),r&&((l=elCreate("p")).innerHTML="<br>",s.parentNode.insertBefore(l,s.nextSibling))}else s.insertBefore(elCreate("br"),e);elRemove(e)}})),elBySelAll("p",r,(function(e){var t=!1;0===e.childNodes.length?t=!0:""===e.textContent?(t=!0,elBySelAll("*",e,(function(e){"SPAN"!==e.nodeName&&(t=!1)}))):0===e.textContent.trim().length&&(elBySelAll("span",e,(function(e){if(!e.hasAttribute("style")||!e.style.length){for(;e.childNodes.length;)e.parentNode.insertBefore(e.childNodes[0],e);elRemove(e)}})),0===e.children.length&&(e.innerHTML="<br>")),t&&elRemove(e)})),r.innerHTML}.bind(this),l=[],r=function(e,t){var n,r,i,o,a={};for(i=0,o=t.length;i<o;i++)n=t[i],r=elAttr(e,n),"style"===n&&0===e.style.length&&0===r.indexOf("font-family")&&(r=r.replace(/"/g,"")),a[n]=r;l.push({element:e,attributes:a})},i=this.clean.convertTags,this.clean.convertTags=function(e,t){var n,o,a=elCreate("div");return a.innerHTML=e,l=[],WCF.System.Event.fireEvent("com.woltlab.wcf.redactor2","convertTags_"+this.$element[0].id,{addToStorage:r,div:a}),elBySelAll("span",a,(function(e){r(e,["style"])})),l.forEach((function(e,t){var n=e.element,l=n.parentNode;for(l.insertBefore(document.createTextNode("###custom"+t+"###"),n),l.insertBefore(document.createTextNode("###/custom"+t+"###"),n.nextSibling);n.childNodes.length;)l.insertBefore(n.childNodes[0],n);l.removeChild(n)})),n=!1,t.links&&this.opts.pasteLinks&&(elBySelAll("a",a,(function(e){e.href&&(e.outerHTML='#@###[a href="'+e.href+'"]###@#'+e.innerHTML+"#@###[/a]###@#")})),n=!0,t.links=!1),o=!1,t.images&&this.opts.pasteImages&&(elBySelAll("img",a,(function(e){var t,n,l,r;if(e.src){for(t='#####[img src="'+e.src+'"',l=0,r=e.attributes.length;l<r;l++)"src"!==(n=e.attributes.item(l)).name&&(t+=" "+n.name+'="'+n.value+'"');e.outerHTML=t+"]#####"}})),o=!0,t.images=!1),a.querySelectorAll("colgroup").forEach((e=>e.remove())),a.querySelectorAll("table, tbody, td, th, thead, tr").forEach((e=>{for(let t=e.attributes.length-1;t>=0;t--){const n=e.attributes.item(t),l=n.name;if(!("TD"!==e.nodeName&&"TH"!==e.nodeName||"colspan"!==l&&"rowspan"!==l)){const e=+n.value;if(!Number.isNaN(e)&&Number.isInteger(e))continue}e.attributes.removeNamedItem(l)}})),e=i.call(this,a.innerHTML,t),o&&(t.images=!0),n&&(t.links=!0),e}.bind(this),o=this.clean.reconvertTags,this.clean.reconvertTags=function(e,t){if(l.length){e=e.replace(/###(\/?)custom(\d+)###/g,'<$1woltlab-custom-tag data-index="$2">');var n=elCreate("div");n.innerHTML=e,elBySelAll("woltlab-custom-tag",n,(function(e){var t,n,r,i=~~elData(e,"index");if(l[i]){for(r in t=l[i],n=elCreate(t.element.nodeName),t.attributes)t.attributes.hasOwnProperty(r)&&elAttr(n,r,t.attributes[r]);for(e.parentNode.insertBefore(n,e);e.childNodes.length;)n.appendChild(e.childNodes[0])}elRemove(e)})),e=n.innerHTML}return(t.links&&this.opts.pasteLinks||t.images&&this.opts.pasteImages)&&(e=(e=e.replace(new RegExp("#@###\\[","gi"),"<")).replace(new RegExp("\\]###@#","gi"),">")),o.call(this,e,t)}.bind(this),this.clean.removeSpans=function(e){return e},a=this.clean.getCurrentType,this.clean.getCurrentType=function(e,t){var n=a.call(this,e,t);return this.utils.isCurrentOrParent(["kbd"])&&(n.inline=!1,n.block=!1,n.encode=!0,n.pre=!0,n.paragraphize=!1,n.images=!1,n.links=!1),n}.bind(this),this.clean.removeEmptyInlineTags,this.clean.removeEmptyInlineTags=function(e){var t=this.opts.inlineTags,n=$("<div/>").html($.parseHTML(e,document,!0)),l=this,r=n.find("span"),i=n.find(t.join(","));return i.filter(":not(span)").removeAttr("style"),i.each((function(){var e=$(this).html();0===this.attributes.length&&l.utils.isEmpty(e)&&$(this).replaceWith((function(){return $(this).contents()}))})),r.each((function(){$(this).html();0===this.attributes.length&&$(this).replaceWith((function(){return $(this).contents()}))})),e=(e=(e=(e=n.html()).replace("\x3c!--?php","<?php")).replace("\x3c!--?","<?")).replace("?--\x3e","?>"),n.remove(),e}.bind(this)},removeRedundantStyles:function(){var e,t=[],n=["del","em","strong","sub","sup","u"];elBySelAll(n.join(","),this.$editor[0],(function(e){elBySelAll(e.nodeName,e,(function(e){t.push(e)}))})),this.opts.pastePlainText||(elBySelAll("span[style]",this.$editor[0],(function(e){["color","font-family","font-size"].forEach((function(n){var l=e.style.getPropertyValue(n);l&&window.getComputedStyle(e.parentNode).getPropertyValue(n)===l&&t.push(e)}))})),t.forEach((function(t){for(e=t.parentNode;t.childNodes.length;)e.insertBefore(t.childNodes[0],t);e.removeChild(t)})))}}}; })(this);