// WoltLabInsert.js
$.Redactor.prototype.WoltLabInsert=function(){"use strict";return{init:function(){var t=this.opts.woltlab.placeholderCallback,e=this.insert.html;this.insert.html=function(i,n){t&&(t=t()),this.placeholder.hide(),this.core.editor().focus();var r=this.selection.block(),l=""===this.$editor[0].innerHTML.replace(/<\/?p>/g,"").replace(/<br>/g,"").replace(/\u200B/g,"").trim();if(e.call(this,i,n),l&&(r=this.$editor[0].firstElementChild),r&&"P"===r.nodeName&&r.nextElementSibling){var s=!1;0===r.childElementCount&&""===r.textContent.replace(/\u200B/g,"").trim()?s=!0:1===r.childElementCount&&"<br>"===r.innerHTML&&(s=!0),s&&elRemove(r)}}.bind(this);var i=this.insert.text;this.insert.text=function(e){t&&(t=t()),i.call(this,e)}.bind(this)}}};
// WoltLabKeydown.js
-$.Redactor.prototype.WoltLabKeydown=function(){"use strict";var e=[];return{init:function(){var e=this.keydown.init;this.keydown.init=function(t){var i=e.call(this,t);if(!(i===!1||t.originalEvent.defaultPrevented||(t=t.originalEvent,39!==t.which||t.ctrlKey||t.shiftKey||t.metaKey||t.altKey))){var n=window.getSelection();if(!n.isCollapsed)return;var o=n.anchorNode;if(o.nodeType!==Node.TEXT_NODE||n.getRangeAt(0).startOffset!==o.textContent.length)return;var r=o.parentNode;if("KBD"!==r.nodeName)return;for(var s=!0,a=r;a&&a!==this.core.editor()[0];){if(null!==a.nextSibling){for(;a.nextSibling&&a.nextSibling.nodeType===Node.TEXT_NODE&&0===a.nextSibling.textContent.length;)a.parentNode.removeChild(a.nextSibling);if(a.nextSibling&&"BR"!==a.nextSibling.nodeName||null!==a.nextSibling.nextSibling){s=!1;break}}a=a.parentNode}s&&r.parentNode.insertBefore(document.createTextNode(""),r.nextSibling)}}.bind(this),this.core.editor().off("keydown.redactor"),this.core.editor().on("keydown.redactor",this.keydown.init.bind(this)),this.keydown.onArrowDown=function(){for(var e=this.WoltLabKeydown._getBlocks(),t=0;t<e.length;t++)if(e[t])return this.keydown.insertAfterLastElement(e[t]),!1}.bind(this),this.keydown.onArrowUp=function(){for(var e=this.WoltLabKeydown._getBlocks(),t=0;t<e.length;t++)if(e[t])return this.keydown.insertBeforeFirstElement(e[t]),!1}.bind(this),this.keydown.onBackspaceAndDeleteAfter=function(e){setTimeout($.proxy(function(){this.code.syncFire=!1,this.keydown.removeEmptyLists(),this.core.editor().find("*[style]").not("span, img, #redactor-image-box, #redactor-image-editter").removeAttr("style"),this.keydown.formatEmpty(e);var t=this.selection.current();"KBD"===t.nodeName&&0===t.innerHTML.length&&elRemove(t),this.code.syncFire=!0},this),1)}.bind(this);var t=function(e){var t=this.core.callback("enter",e);if(t===!1)return e.preventDefault(),!1;if(this.keydown.blockquote&&this.keydown.exitFromBlockquote(e)===!0)return!1;if(this.keydown.pre)return this.keydown.insertNewLine(e);if(this.keydown.blockquote||this.keydown.figcaption)return this.keydown.insertBreakLine(e);if(this.keydown.figure)setTimeout($.proxy(function(){this.keydown.replaceToParagraph("FIGURE")},this),1);else if(this.keydown.block){if(setTimeout($.proxy(function(){this.keydown.replaceToParagraph("DIV")},this),1),"LI"===this.keydown.block.tagName){var i=this.selection.current(),n=$(i).closest("li",this.$editor[0]),o=n.parentsUntil(this.$editor[0],"ul,ol").last();if(0!==n.length&&this.utils.isEmpty(n.html())&&0===o.next().length&&this.utils.isEmpty(o.find("li").last().html())){o.find("li").last().remove();var r=$(this.opts.emptyHtml);return o.after(r),this.caret.start(r),!1}}}else if(!this.keydown.block)return this.keydown.insertParagraph(e);return this.detect.isFirefox()&&this.utils.isInline(this.keydown.parent)?(this.keydown.insertBreakLine(e),void setTimeout(function(){for(var e=this.selection.block(),t=this.selection.inline();t&&t!==e;){if("A"===t.nodeName){var i=!1;if(0===t.childNodes.length?i=!0:""===t.textContent.replace(/\u200B/g,"")&&(i=!0,elBySelAll("*",t,function(e){"SPAN"!==e.nodeName&&(i=!1)})),i){for(;t.childNodes.length;)t.parentNode.insertBefore(t.childNodes[0],t);elRemove(t);break}}t=t.parentNode}}.bind(this),1)):void 0}.bind(this);this.keydown.onEnter=function(e){var i=this.keydown.blockquote;i&&(this.keydown.blockquote=!1);var n=t.call(this,e);return i&&(this.keydown.blockquote=i),n}.bind(this),this.keydown.replaceToParagraph=function(e){var t=this.selection.block(),i=t.innerHTML.replace(/<br\s?\/?>/gi,"");if(t.tagName===e&&this.utils.isEmpty(i)&&!$(t).hasClass("redactor-in")){var n=document.createElement("p");$(t).replaceWith(n);var o=document.createRange();o.setStart(n,0);var r=document.createTextNode("");o.insertNode(r),o.setStartAfter(r),o.collapse(!0);var s=window.getSelection();return s.removeAllRanges(),s.addRange(o),!1}"P"===t.tagName&&$(t).removeAttr("style")}.bind(this),this.keydown.onShiftEnter=function(e){return this.buffer.set(),this.keydown.pre?this.keydown.insertNewLine(e):this.insert.raw("<br>")}.bind(this);var i=this.keydown.onTab;this.keydown.onTab=function(e,t){return this.keydown.pre||0!==$(this.selection.current()).closest("ul, ol",this.core.editor()[0]).length?i.call(this,e,t):!0}.bind(this);var n=this.keydown.formatEmpty;this.keydown.formatEmpty=function(e){for(var t,i=this.$editor[0],o=0,r=i.childElementCount;r>o;o++)if(t=i.children[o],"P"!==t.nodeName&&this.utils.isBlockTag(t.nodeName))return;return n.call(this,e)}.bind(this),require(["Core","Environment"],function(e,t){if("desktop"===t.platform()){var i=this.$editor[0].closest("form, .message");if(null!==i){var n=elBySel(".formSubmit",i);if(null!==n){var o=elBySel('input[type="submit"], button[data-type="save"], button[accesskey="s"]',n);o&&(o.removeAttribute("accesskey"),this.WoltLabEvent.register("keydown",function(t){if(83===t.event.which){var i=!1;window.navigator.platform.match(/^Mac/)?t.event.ctrlKey&&t.event.altKey&&(i=!0):t.event.altKey&&!t.event.ctrlKey&&(i=!0),i&&(t.cancel=!0,"function"==typeof o.click?o.click():e.triggerEvent(o,WCF_CLICK_EVENT))}}.bind(this)))}}}}.bind(this))},register:function(t){-1===e.indexOf(t)&&e.push(t)},_getBlocks:function(){for(var t=[this.keydown.blockquote,this.keydown.pre,this.keydown.figcaption],i=0,n=e.length;n>i;i++)t.push(this.utils.isTag(this.keydown.current,e[i]));return t}}};
+$.Redactor.prototype.WoltLabKeydown=function(){"use strict";var e=[];return{init:function(){var e=this.keydown.init;this.keydown.init=function(t){var i=e.call(this,t);if(!(i===!1||t.originalEvent.defaultPrevented||(t=t.originalEvent,39!==t.which||t.ctrlKey||t.shiftKey||t.metaKey||t.altKey))){var n=window.getSelection();if(!n.isCollapsed)return;var o=n.anchorNode;if(o.nodeType!==Node.TEXT_NODE||n.getRangeAt(0).startOffset!==o.textContent.length)return;var r=o.parentNode;if("KBD"!==r.nodeName)return;for(var s=!0,l=r;l&&l!==this.core.editor()[0];){if(null!==l.nextSibling){for(;l.nextSibling&&l.nextSibling.nodeType===Node.TEXT_NODE&&0===l.nextSibling.textContent.length;)l.parentNode.removeChild(l.nextSibling);if(l.nextSibling&&"BR"!==l.nextSibling.nodeName||null!==l.nextSibling.nextSibling){s=!1;break}}l=l.parentNode}s&&r.parentNode.insertBefore(document.createTextNode(""),r.nextSibling)}}.bind(this),this.core.editor().off("keydown.redactor"),this.core.editor().on("keydown.redactor",this.keydown.init.bind(this)),this.keydown.onArrowDown=function(){for(var e=this.WoltLabKeydown._getBlocks(),t=0;t<e.length;t++)if(e[t])return this.keydown.insertAfterLastElement(e[t]),!1}.bind(this),this.keydown.onArrowUp=function(){for(var e=this.WoltLabKeydown._getBlocks(),t=0;t<e.length;t++)if(e[t])return this.keydown.insertBeforeFirstElement(e[t]),!1}.bind(this);var t=function(e){var t=this.core.callback("enter",e);if(t===!1)return e.preventDefault(),!1;if(this.keydown.blockquote&&this.keydown.exitFromBlockquote(e)===!0)return!1;if(this.keydown.pre)return this.keydown.insertNewLine(e);if(this.keydown.blockquote||this.keydown.figcaption)return this.keydown.insertBreakLine(e);if(this.keydown.figure)setTimeout($.proxy(function(){this.keydown.replaceToParagraph("FIGURE")},this),1);else if(this.keydown.block){if(setTimeout($.proxy(function(){this.keydown.replaceToParagraph("DIV")},this),1),"LI"===this.keydown.block.tagName){var i=this.selection.current(),n=$(i).closest("li",this.$editor[0]),o=n.parentsUntil(this.$editor[0],"ul,ol").last();if(0!==n.length&&this.utils.isEmpty(n.html())&&0===o.next().length&&this.utils.isEmpty(o.find("li").last().html())){o.find("li").last().remove();var r=$(this.opts.emptyHtml);return o.after(r),this.caret.start(r),!1}}}else if(!this.keydown.block)return this.keydown.insertParagraph(e);return this.detect.isFirefox()&&this.utils.isInline(this.keydown.parent)?(this.keydown.insertBreakLine(e),void setTimeout(function(){for(var e=this.selection.block(),t=this.selection.inline();t&&t!==e;){if("A"===t.nodeName){var i=!1;if(0===t.childNodes.length?i=!0:""===t.textContent.replace(/\u200B/g,"")&&(i=!0,elBySelAll("*",t,function(e){"SPAN"!==e.nodeName&&(i=!1)})),i){for(;t.childNodes.length;)t.parentNode.insertBefore(t.childNodes[0],t);elRemove(t);break}}t=t.parentNode}}.bind(this),1)):void 0}.bind(this);this.keydown.onEnter=function(e){var i=this.keydown.blockquote;i&&(this.keydown.blockquote=!1);var n=t.call(this,e);return i&&(this.keydown.blockquote=i),n}.bind(this),this.keydown.replaceToParagraph=function(e){var t=this.selection.block(),i=t.innerHTML.replace(/<br\s?\/?>/gi,"");if(t.tagName===e&&this.utils.isEmpty(i)&&!$(t).hasClass("redactor-in")){var n=document.createElement("p");$(t).replaceWith(n);var o=document.createRange();o.setStart(n,0);var r=document.createTextNode("");o.insertNode(r),o.setStartAfter(r),o.collapse(!0);var s=window.getSelection();return s.removeAllRanges(),s.addRange(o),!1}"P"===t.tagName&&$(t).removeAttr("style")}.bind(this),this.keydown.onShiftEnter=function(e){return this.buffer.set(),this.keydown.pre?this.keydown.insertNewLine(e):this.insert.raw("<br>")}.bind(this);var i=this.keydown.onTab;this.keydown.onTab=function(e,t){return this.keydown.pre||0!==$(this.selection.current()).closest("ul, ol",this.core.editor()[0]).length?i.call(this,e,t):!0}.bind(this);var n=this.keydown.formatEmpty;this.keydown.formatEmpty=function(e){for(var t,i=this.$editor[0],o=0,r=i.childElementCount;r>o;o++)if(t=i.children[o],"P"!==t.nodeName&&this.utils.isBlockTag(t.nodeName))return;return n.call(this,e)}.bind(this),require(["Core","Environment"],function(e,t){if("desktop"===t.platform()){var i=this.$editor[0].closest("form, .message");if(null!==i){var n=elBySel(".formSubmit",i);if(null!==n){var o=elBySel('input[type="submit"], button[data-type="save"], button[accesskey="s"]',n);o&&(o.removeAttribute("accesskey"),this.WoltLabEvent.register("keydown",function(t){if(83===t.event.which){var i=!1;window.navigator.platform.match(/^Mac/)?t.event.ctrlKey&&t.event.altKey&&(i=!0):t.event.altKey&&!t.event.ctrlKey&&(i=!0),i&&(t.cancel=!0,"function"==typeof o.click?o.click():e.triggerEvent(o,WCF_CLICK_EVENT))}}.bind(this)))}}}}.bind(this)),this.WoltLabKeydown._handleBackspaceAndDelete()},register:function(t){-1===e.indexOf(t)&&e.push(t)},_getBlocks:function(){for(var t=[this.keydown.blockquote,this.keydown.pre,this.keydown.figcaption],i=0,n=e.length;n>i;i++)t.push(this.utils.isTag(this.keydown.current,e[i]));return t},_handleBackspaceAndDelete:function(){var e=function(e){return null===elBySel("img",e)&&""===e.textContent.replace(/\u200B/g,"").trim()},t=function(t){var i,n=this.selection.block();if(-1!==n.nodeName.indexOf("-")&&e(n))i=n.parentNode,i.insertBefore(this.marker.get(),n.nextSibling),elRemove(n),this.selection.restore();else if(i=n&&"P"===n.nodeName?n.parentNode:null,i&&-1!==i.nodeName.indexOf("-")){var o=window.getSelection().getRangeAt(0),r=document.createRange();r.setStartBefore(n),r.setEnd(o.startContainer,o.startOffset);var s=r.cloneContents(),l=elCreate("div");if(l.appendChild(s),e(l)){t.preventDefault();var a=n.previousElementSibling,d=null;if(a)d=e(a);else for(i=n;(i=i.parentNode)&&i!==this.$editor[0];)if(a=i.previousElementSibling){d=!1;break}if(d)elRemove(a);else if(null!==d){var h=n.parentNode;if("P"===a.nodeName){for(a.appendChild(this.marker.get());n.childNodes.length;)a.appendChild(n.childNodes[0]);elRemove(n),this.selection.restore()}else a.appendChild(n),n.insertBefore(this.marker.get(),n.firstChild),this.selection.restore();e(h)&&elRemove(h)}else null===d&&(i=n.parentNode,e(i)&&elRemove(i))}}}.bind(this),i=function(t){var i,n=this.selection.block();if(-1!==n.nodeName.indexOf("-")&&e(n))i=n.parentNode,i.insertBefore(this.marker.get(),n.nextSibling),elRemove(n),this.selection.restore();else if(i=n&&"P"===n.nodeName?n.parentNode:null,i&&-1!==i.nodeName.indexOf("-")){var o=window.getSelection().getRangeAt(0),r=document.createRange();r.setStart(o.startContainer,o.startOffset),r.setEndAfter(n);var s=r.cloneContents(),l=elCreate("div");if(l.appendChild(s),e(l)){t.preventDefault();var a=n.nextElementSibling,d=null;if(a)d=e(a);else for(i=n;(i=i.parentNode)&&i!==this.$editor[0];)if(a=i.nextElementSibling){d=!1;break}if(d)elRemove(a);else if(null!==d){var h=a.parentNode;if("P"===a.nodeName){for(;a.childNodes.length;)n.appendChild(a.childNodes[0]);elRemove(a)}else{if(n.appendChild(this.marker.get()),i=n.parentNode,-1!==a.nodeName.indexOf("-")){var c=a.firstElementChild;if(c&&"P"===c.nodeName){for(;c.childNodes.length;)n.appendChild(c.childNodes[0]);a.removeChild(c),e(a)&&elRemove(a)}}else i.insertBefore(a,n.nextSibling);this.selection.restore()}e(h)&&elRemove(h)}else null===d&&(i=n.parentNode,e(i)&&elRemove(i))}}}.bind(this);this.keydown.onBackspaceAndDeleteAfter=function(e){this.detect.isFirefox()&&this.selection.isCollapsed()&&(e.which===this.keyCode.BACKSPACE?t(e):e.which===this.keyCode.DELETE&&i(e)),setTimeout($.proxy(function(){this.code.syncFire=!1,this.keydown.removeEmptyLists(),this.core.editor().find("*[style]").not("span, img, #redactor-image-box, #redactor-image-editter").removeAttr("style"),this.keydown.formatEmpty(e);var t=this.selection.current();"KBD"===t.nodeName&&0===t.innerHTML.length&&elRemove(t),this.code.syncFire=!0},this),1)}.bind(this)}}};
+// WoltLabLine.js
+$.Redactor.prototype.WoltLabLine=function(){"use strict";return{init:function(){this.line.removeOnBackspace=function(){if(this.utils.isCollapsed()){var t=$(this.selection.block());if(0!==t.length&&this.utils.isStartOfElement(t)){var i=t.prev();i.length&&"HR"===i[0].tagName&&(e.preventDefault(),i.remove())}}}.bind(this)}}};
// WoltLabLink.js
$.Redactor.prototype.WoltLabLink=function(){"use strict";var i=null;return{init:function(){this.link.show=this.WoltLabLink.show.bind(this),require(["WoltLabSuite/Core/Ui/Redactor/Link"],function(t){i=t})},show:function(t){"undefined"!=typeof t&&t.preventDefault&&t.preventDefault();var e=this.selection.is();this.selection.save(),this.observe.closeAllTooltip();var s=this.link.is();i.showDialog({insert:s===!1,submitCallback:function(){var i=this.link.buildLinkFromModal();return i===!1?!1:(this.selection.restore(),this.link.insert(i,!0),!0)}.bind(this)}),e&&this.selection.restore();var n=this.link.buildLinkFromElement(s);e&&this.selection.save(),n.url=this.link.removeSelfHostFromUrl(n.url),this.link.setModalValues(n),this.detect.isDesktop()&&$("#redactor-link-url").focus()}}};
// WoltLabMedia.js