(function (window, undefined) { $.Redactor.prototype.WoltLabInsert=function(){"use strict";return{init:function(){var e=this.opts.woltlab.placeholderCallback,t=this.insert.html;this.insert.html=function(o,r){e&&(e=e());var n=window.getSelection();if(n.rangeCount&&"IMG"===n.anchorNode.nodeName&&this.caret.after(n.anchorNode),this.placeholder.hide(),this.core.editor().focus(),this.detect.isFirefox()){var i=n.anchorNode.nodeType===Node.TEXT_NODE?n.anchorNode.parentNode:n.anchorNode;null===i.closest(".redactor-layer")&&(this.selection.restore(),i=n.anchorNode.nodeType===Node.TEXT_NODE?n.anchorNode.parentNode:n.anchorNode,null===i.closest(".redactor-layer")&&(this.WoltLabCaret.endOfEditor(),this.selection.save()))}var a=this.selection.block(),s=""===this.$editor[0].innerHTML.replace(/<\/?p>/g,"").replace(/<br>/g,"").replace(/\u200B/g,"").trim();if(t.call(this,o,r),s&&(a=this.$editor[0].firstElementChild),a&&"P"===a.nodeName&&a.nextElementSibling){var c=!1;0===a.childElementCount&&""===a.textContent.replace(/\u200B/g,"").trim()?c=!0:1===a.childElementCount&&"<br>"===a.innerHTML&&(c=!0),c&&elRemove(a)}n.rangeCount&&"IMG"===n.anchorNode.nodeName&&this.caret.after(n.anchorNode)}.bind(this);var o=this.insert.text;this.insert.text=function(t){e&&(e=e()),this.core.editor().focus(),this.selection.restore(),elClosest(window.getSelection().anchorNode,".redactor-layer")!==this.core.editor()[0]&&this.WoltLabCaret.endOfEditor(),o.call(this,t),this.selection.saveInstant()}.bind(this),this.insert.placeHtml=function(e){var t=!1;e.forEach(function(e){e instanceof Element&&e.classList.contains("woltlab-bbcode-marker")&&(t=!0)});var o=document.createElement("span");o.id="redactor-insert-marker",o=this.insert.node(o),$(o).before(e),t||(this.selection.restore(),this.caret.after(o)),$(o).remove()}.bind(this)}}}; })(this);
// plugins/WoltLabKeydown.js
-(function (window, undefined) { $.Redactor.prototype.WoltLabKeydown=function(){"use strict";var e=!1,t=[];return{init:function(){var t=window.getSelection();require(["Environment"],function(t){e="safari"===t.browser()});var i=this.keydown.init;this.keydown.init=function(e){var n;if(this.detect.isFirefox()&&t.isCollapsed&&e.which===this.keyCode.BACKSPACE&&(n=t.anchorNode,n.nodeType===Node.ELEMENT_NODE&&t.anchorOffset>0&&(n=n.childNodes[t.anchorOffset-1]),n.nodeType===Node.TEXT_NODE&&""===n.textContent)){for(var o=[],r=n;r=r.previousSibling;){if(r.nodeType===Node.ELEMENT_NODE){"IMG"!==r.nodeName&&(o=[]);break}if(r.nodeType===Node.TEXT_NODE){var l=r.textContent;if(""!==l&&""!==l){o=[];break}o.push(r)}}o.length&&o.forEach(elRemove)}if((e.originalEvent.which===this.keyCode.BACKSPACE||e.originalEvent.which===this.keyCode.DELETE)&&t.isCollapsed){var s=this.selection.block();if("P"===s.nodeName){if(this.list.combineAfterAndBefore(s))return void e.originalEvent.preventDefault();if(this.utils.isEmpty(s.innerHTML)&&s.previousElementSibling!==s.nextElementSibling){var a=null,d=null;return e.originalEvent.which===this.keyCode.BACKSPACE?null===s.previousElementSibling?d=s.nextElementSibling:a=s.previousElementSibling:null===s.nextElementSibling?a=s.previousElementSibling:d=s.nextElementSibling,elRemove(s),null===d?("OL"!==a.nodeName&&"UL"!==a.nodeName||(a=a.lastElementChild),this.caret.end(a)):("OL"!==d.nodeName&&"UL"!==d.nodeName||(d=d.firstElementChild),this.caret.start(d)),void e.originalEvent.preventDefault()}}else{if(e.originalEvent.which===this.keyCode.DELETE&&-1!==["H1","H2","H3","H4","H5","H6"].indexOf(s.nodeName)&&this.utils.isEmpty(s.innerHTML)){var h=s.nextElementSibling;return h?h=s.nextElementSibling:(h=elCreate("p"),h.innerHTML=this.opts.invisibleSpace,s.parentNode.appendChild(h)),s.parentNode.removeChild(s),this.caret.start(h),void e.originalEvent.preventDefault()}if(this.detect.isWebkit()&&"LI"===s.nodeName&&e.which===this.keyCode.DELETE){var c=t.anchorNode;if(c.nodeType===Node.TEXT_NODE&&c.textContent.length===t.anchorOffset&&c.parentNode.lastChild===c){var f=s.nextElementSibling;if(f&&"LI"===f.nodeName){for(this.buffer.set(),this.selection.save();f.childNodes.length;)s.appendChild(f.childNodes[0]);return elRemove(f),this.selection.restore(),void e.preventDefault()}}}}}var u=null;if(e.which===this.keyCode.BACKSPACE&&this.detect.isFirefox()){var m=this.selection.block();if(m&&"P"===m.tagName&&this.utils.isStartOfElement(m)){var v=m.previousElementSibling;if(v&&("OL"===v.nodeName||"UL"===v.nodeName)){this.buffer.set(),this.selection.save();for(var p=v.lastElementChild;m.childNodes.length;)p.appendChild(m.childNodes[0]);return elRemove(m),this.selection.restore(),void e.preventDefault()}v&&"P"===v.nodeName&&null!==(u=v.lastElementChild)&&"BR"!==u.nodeName&&(u=null)}}if(!1===i.call(this,e)||e.originalEvent.defaultPrevented){if(null!==u&&this.detect.isFirefox()){var g=t.getRangeAt(0);1===g.startOffset&&g.startContainer.firstElementChild===u&&elRemove(u)}}else if(e=e.originalEvent,!(39!==e.which||e.ctrlKey||e.shiftKey||e.metaKey||e.altKey)){if(!t.isCollapsed)return;var E=t.anchorNode;if(E.nodeType!==Node.TEXT_NODE||t.getRangeAt(0).startOffset!==E.textContent.length)return;var N=E.parentNode;if("KBD"!==N.nodeName)return;var y=!0;for(n=N;n&&n!==this.core.editor()[0];){if(null!==n.nextSibling){for(;n.nextSibling&&n.nextSibling.nodeType===Node.TEXT_NODE&&0===n.nextSibling.textContent.length;)n.parentNode.removeChild(n.nextSibling);if(n.nextSibling&&"BR"!==n.nextSibling.nodeName||null!==n.nextSibling.nextSibling){y=!1;break}}n=n.parentNode}y&&N.parentNode.insertBefore(document.createTextNode(""),N.nextSibling)}}.bind(this);var n=window.navigator.userAgent.toLowerCase();-1!==n.indexOf("linux")&&-1!==n.indexOf("android")&&-1!==n.indexOf("chrome")&&(this.keydown.checkEvents=function(){this.core.addEvent(!1)}.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,t,i=this.WoltLabKeydown._getBlocks(),n=0;n<i.length;n++)if(t=i[n]){if(!this.utils.isEndOfElement(t))continue;if(null!==(e=t.nextElementSibling)&&"P"===e.nodeName)break;return void this.keydown.insertAfterLastElement(t)}}.bind(this),this.keydown.onArrowUp=function(){for(var e,t,i=this.WoltLabKeydown._getBlocks(),n=0;n<i.length;n++)if(t=i[n]){if(!this.utils.isStartOfElement())break;if(null!==(e=t.previousElementSibling)&&"P"!==e.nodeName){var o=$(this.opts.emptyHtml)[0];t.parentNode.insertBefore(o,t),this.caret.end(o);break}return void this.keydown.insertBeforeFirstElement(t)}}.bind(this);var o=function(t){if(!1===this.core.callback("enter",t))return t.preventDefault(),!1;if(this.keydown.blockquote&&!0===this.keydown.exitFromBlockquote(t))return!1;if(this.keydown.pre)return this.keydown.insertNewLine(t);if(this.keydown.blockquote||this.keydown.figcaption)return this.keydown.insertBreakLine(t);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=elClosest(i,"li");if(this.utils.isRedactorParent(n)&&this.utils.isEmpty(n.innerHTML)&&null===n.nextElementSibling&&(n.innerHTML=e?"<br>":"",e)){var o=document.createRange();o.selectNodeContents(n),o.collapse(!1);var r=window.getSelection();r.removeAllRanges(),r.addRange(o)}}}else if(!this.keydown.block)return this.keydown.insertParagraph(t);return this.detect.isFirefox()&&this.utils.isInline(this.keydown.parent)?(this.keydown.insertBreakLine(t),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,"").trim()&&(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 t=this.keydown.blockquote;t&&(this.keydown.blockquote=!1);var i=o.call(this,e);return t&&(this.keydown.blockquote=t),i}.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 l=window.getSelection();return l.removeAllRanges(),l.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 r=this.keydown.onTab;this.keydown.onTab=function(e,i){if(!this.keydown.pre){var n=$(this.selection.current()).closest("ul, ol, td",this.core.editor()[0]);if(0===n.length)return!0;if(n=n[0],"TD"===n.nodeName){var o=null;if(e.originalEvent.shiftKey?null===(o=n.previousElementSibling)&&null!==(o=n.parentNode.previousElementSibling)&&(o=o.lastElementChild):null===(o=n.nextElementSibling)&&(o=n.parentNode.nextElementSibling,null===o&&(this.table.addRowBelow(),o=n.parentNode.nextElementSibling),o=o.firstElementChild),null!==o)if(this.utils.isEmpty(o.innerHTML))this.caret.end(o);else{var l=document.createRange();l.selectNodeContents(o),t.removeAllRanges(),t.addRange(l)}return e.originalEvent.preventDefault(),!1}}return r.call(this,e,i)}.bind(this);var l=this.keydown.formatEmpty;this.keydown.formatEmpty=function(e){for(var t,i=this.$editor[0],n=0,o=i.childElementCount;n<o;n++)if(t=i.children[n],"P"!==t.nodeName&&this.utils.isBlockTag(t.nodeName))return;return l.call(this,e)}.bind(this);var s=this.keydown.removeInvisibleSpace;this.keydown.removeInvisibleSpace=function(){this.keydown.current!==this.$editor[0]&&s.call(this)}.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(e){-1===t.indexOf(e)&&t.push(e)},_getBlocks:function(){for(var e=[this.keydown.blockquote,this.keydown.pre,this.keydown.figcaption],i=0,n=t.length;i<n;i++)e.push(this.utils.isTag(this.keydown.current,t[i]));return e},_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(n)if("TD"===n.nodeName){var o=n.innerHTML;""===o?t.preventDefault():""===o&&(t.preventDefault(),n.innerHTML="")}else 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)&&-1!==i.nodeName.indexOf("-")){var r=window.getSelection().getRangeAt(0),l=document.createRange();l.setStartBefore(n),l.setEnd(r.startContainer,r.startOffset);var s=l.cloneContents(),a=elCreate("div");if(a.appendChild(s),e(a)){t.preventDefault();var d=n.previousElementSibling,h=null;if(d)h=e(d);else for(i=n;(i=i.parentNode)&&i!==this.$editor[0];)if(d=i.previousElementSibling){h=!1;break}if(h)elRemove(d);else if(null!==h){var c=n.parentNode;if("P"===d.nodeName){d.appendChild(this.marker.get());for(var f;n.childNodes.length;){if(f=n.childNodes[0],"BR"===f.nodeName){elRemove(f);break}d.appendChild(f)}0===n.childNodes.length&&elRemove(n),this.selection.restore()}else d.appendChild(n),n.insertBefore(this.marker.get(),n.firstChild),this.selection.restore();e(c)&&elRemove(c)}else null===h&&(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)&&-1!==i.nodeName.indexOf("-")){var o=window.getSelection().getRangeAt(0),r=document.createRange();r.setStart(o.startContainer,o.startOffset),r.setEndAfter(n);var l=r.cloneContents(),s=elCreate("div");if(s.appendChild(l),e(s)){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),n=function(){return this.opts.blockTags.filter(function(e){return-1!==e.indexOf("-")}).join(",")}.bind(this),o=[],r=function(){elBySelAll(n(),this.core.editor()[0],function(e){null!==e.parentNode&&-1!==o.indexOf(e)&&["nextElementSibling","previousElementSibling"].forEach(function(t){for(var i,n=e[t];null!==n&&n.nodeName===e.nodeName&&-1===o.indexOf(n);){if("previousElementSibling"===t)for(var r=n.childNodes.length-1;r>=0;r--)e.insertBefore(n.childNodes[r],e.firstChild);else for(;n.childNodes.length>0;)e.appendChild(n.childNodes[0]);i=n[t],elRemove(n),n=i}})}),o=[]}.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):e.which!==this.keyCode.BACKSPACE&&e.which!==this.keyCode.DELETE||elBySelAll(n(),this.core.editor()[0],function(e){o.push(e)}));var l=!1;if(e.which===this.keyCode.BACKSPACE&&this.selection.isCollapsed()&&this.detect.isWebkit()){var s=this.selection.block();!1!==s&&"PRE"===s.nodeName&&(l=!0)}setTimeout($.proxy(function(){var t;if(o.length>0&&r(),l){var i=this.selection.block();if((!1===i||"PRE"!==i.nodeName)&&(t=this.selection.current(),t.nodeType===Node.TEXT_NODE&&t.nextSibling&&"SPAN"===t.nextSibling.nodeName)){var n=t.nextSibling;if(-1!==n.style.getPropertyValue("font-family").indexOf("monospace")&&"pre-wrap"===n.style.getPropertyValue("white-space")){for(;n.childNodes.length;)n.parentNode.insertBefore(n.childNodes[0],n);elRemove(n)}}}this.code.syncFire=!1,this.keydown.removeEmptyLists();var s="";0!==this.opts.keepStyleAttr.length&&(s=","+this.opts.keepStyleAttr.join(",")),this.core.editor().find("*[style]").not("span, img, figure, iframe, #redactor-image-box, #redactor-image-editter, [data-redactor-style-cache], [data-redactor-span]"+s).removeAttr("style"),this.keydown.formatEmpty(e),t=this.selection.current(),"KBD"===t.nodeName&&0===t.innerHTML.length&&elRemove(t),this.code.syncFire=!0},this),1)}.bind(this)}}}; })(this);
+(function (window, undefined) { $.Redactor.prototype.WoltLabKeydown=function(){"use strict";var e=!1,t=[];return{init:function(){var t=window.getSelection();require(["Environment"],function(t){e="safari"===t.browser()});var i=this.keydown.init;this.keydown.init=function(e){var n;if(this.detect.isFirefox()&&t.isCollapsed&&e.which===this.keyCode.BACKSPACE&&(n=t.anchorNode,n.nodeType===Node.ELEMENT_NODE&&t.anchorOffset>0&&(n=n.childNodes[t.anchorOffset-1]),n.nodeType===Node.TEXT_NODE&&""===n.textContent)){for(var o=[],r=n;r=r.previousSibling;){if(r.nodeType===Node.ELEMENT_NODE){"IMG"!==r.nodeName&&(o=[]);break}if(r.nodeType===Node.TEXT_NODE){var l=r.textContent;if(""!==l&&""!==l){o=[];break}o.push(r)}}o.length&&o.forEach(elRemove)}if((e.originalEvent.which===this.keyCode.BACKSPACE||e.originalEvent.which===this.keyCode.DELETE)&&t.isCollapsed){var s=this.selection.block();if("P"===s.nodeName){if(this.list.combineAfterAndBefore(s))return void e.originalEvent.preventDefault();if(this.utils.isEmpty(s.innerHTML)&&s.previousElementSibling!==s.nextElementSibling){var a=null,d=null;return e.originalEvent.which===this.keyCode.BACKSPACE?null===s.previousElementSibling?d=s.nextElementSibling:a=s.previousElementSibling:null===s.nextElementSibling?a=s.previousElementSibling:d=s.nextElementSibling,elRemove(s),null===d?("OL"!==a.nodeName&&"UL"!==a.nodeName||(a=a.lastElementChild),this.caret.end(a)):("OL"!==d.nodeName&&"UL"!==d.nodeName||(d=d.firstElementChild),this.caret.start(d)),void e.originalEvent.preventDefault()}}else{if(e.originalEvent.which===this.keyCode.DELETE&&-1!==["H1","H2","H3","H4","H5","H6"].indexOf(s.nodeName)&&this.utils.isEmpty(s.innerHTML)){var h=s.nextElementSibling;return h?h=s.nextElementSibling:(h=elCreate("p"),h.innerHTML=this.opts.invisibleSpace,s.parentNode.appendChild(h)),s.parentNode.removeChild(s),this.caret.start(h),void e.originalEvent.preventDefault()}if(this.detect.isWebkit()&&"LI"===s.nodeName&&e.which===this.keyCode.DELETE){var c=t.anchorNode;if(c.nodeType===Node.TEXT_NODE&&c.textContent.length===t.anchorOffset&&c.parentNode.lastChild===c){var f=s.nextElementSibling;if(f&&"LI"===f.nodeName){for(this.buffer.set(),this.selection.save();f.childNodes.length;)s.appendChild(f.childNodes[0]);return elRemove(f),this.selection.restore(),void e.preventDefault()}}}}}var u=null;if(e.which===this.keyCode.BACKSPACE&&this.detect.isFirefox()){var m=this.selection.block();if(m&&"P"===m.tagName&&this.utils.isStartOfElement(m)){var v=m.previousElementSibling;if(v&&("OL"===v.nodeName||"UL"===v.nodeName)){this.buffer.set(),this.selection.save();for(var p=v.lastElementChild;m.childNodes.length;)p.appendChild(m.childNodes[0]);return elRemove(m),this.selection.restore(),void e.preventDefault()}v&&"P"===v.nodeName&&null!==(u=v.lastElementChild)&&"BR"!==u.nodeName&&(u=null)}}if(!1===i.call(this,e)||e.originalEvent.defaultPrevented){if(null!==u&&this.detect.isFirefox()){var g=t.getRangeAt(0);1===g.startOffset&&g.startContainer.firstElementChild===u&&elRemove(u)}}else if(e=e.originalEvent,!(39!==e.which||e.ctrlKey||e.shiftKey||e.metaKey||e.altKey)){if(!t.isCollapsed)return;var b=t.anchorNode;if(b.nodeType!==Node.TEXT_NODE||t.getRangeAt(0).startOffset!==b.textContent.length)return;var y=b.parentNode;if("KBD"!==y.nodeName)return;var E=!0;for(n=y;n&&n!==this.core.editor()[0];){if(null!==n.nextSibling){for(;n.nextSibling&&n.nextSibling.nodeType===Node.TEXT_NODE&&0===n.nextSibling.textContent.length;)n.parentNode.removeChild(n.nextSibling);if(n.nextSibling&&"BR"!==n.nextSibling.nodeName||null!==n.nextSibling.nextSibling){E=!1;break}}n=n.parentNode}E&&y.parentNode.insertBefore(document.createTextNode(""),y.nextSibling)}}.bind(this);var n=window.navigator.userAgent.toLowerCase();-1!==n.indexOf("linux")&&-1!==n.indexOf("android")&&-1!==n.indexOf("chrome")&&(this.keydown.checkEvents=function(){this.core.addEvent(!1)}.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,t,i=this.WoltLabKeydown._getBlocks(),n=0;n<i.length;n++)if(t=i[n]){if(!this.utils.isEndOfElement(t))continue;if(null!==(e=t.nextElementSibling)&&"P"===e.nodeName)break;return void this.keydown.insertAfterLastElement(t)}}.bind(this),this.keydown.onArrowUp=function(){for(var e,t,i=this.WoltLabKeydown._getBlocks(),n=0;n<i.length;n++)if(t=i[n]){if(!this.utils.isStartOfElement())break;if(null!==(e=t.previousElementSibling)&&"P"!==e.nodeName){var o=$(this.opts.emptyHtml)[0];t.parentNode.insertBefore(o,t),this.caret.end(o);break}return void this.keydown.insertBeforeFirstElement(t)}}.bind(this);var o=function(t){if(!1===this.core.callback("enter",t))return t.preventDefault(),!1;if(this.keydown.blockquote&&!0===this.keydown.exitFromBlockquote(t))return!1;if(this.keydown.pre)return this.keydown.insertNewLine(t);if(this.keydown.blockquote||this.keydown.figcaption)return this.keydown.insertBreakLine(t);if(this.keydown.figure)setTimeout($.proxy(function(){this.keydown.replaceToParagraph("FIGURE")},this),1);else if(this.keydown.block){var i=null;if(this.detect.isFirefox()&&"P"===this.keydown.block.nodeName&&s.isCollapsed){var n=elClosest(s.getRangeAt(0).startContainer,"a");null!==n&&null===elBySel("br",n)&&(i=this.keydown.block)}if(setTimeout($.proxy(function(){if(this.keydown.replaceToParagraph("DIV"),null!==i&&null!==i.previousElementSibling){var e=[];if(elBySelAll("a",i.previousElementSibling,function(t){e.push(t)}),e.length){var t=e[e.length-1],n=elBySel("br",t);null!==n&&elRemove(n)}}},this),1),"LI"===this.keydown.block.tagName){var o=this.selection.current(),r=elClosest(o,"li");if(this.utils.isRedactorParent(r)&&this.utils.isEmpty(r.innerHTML)&&null===r.nextElementSibling&&(r.innerHTML=e?"<br>":"",e)){var l=document.createRange();l.selectNodeContents(r),l.collapse(!1);var s=window.getSelection();s.removeAllRanges(),s.addRange(l)}}}else if(!this.keydown.block)return this.keydown.insertParagraph(t);return this.detect.isFirefox()&&this.utils.isInline(this.keydown.parent)?(this.keydown.insertBreakLine(t),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,"").trim()&&(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 t=this.keydown.blockquote;t&&(this.keydown.blockquote=!1);var i=o.call(this,e);return t&&(this.keydown.blockquote=t),i}.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 l=window.getSelection();return l.removeAllRanges(),l.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 r=this.keydown.onTab;this.keydown.onTab=function(e,i){if(!this.keydown.pre){var n=$(this.selection.current()).closest("ul, ol, td",this.core.editor()[0]);if(0===n.length)return!0;if(n=n[0],"TD"===n.nodeName){var o=null;if(e.originalEvent.shiftKey?null===(o=n.previousElementSibling)&&null!==(o=n.parentNode.previousElementSibling)&&(o=o.lastElementChild):null===(o=n.nextElementSibling)&&(o=n.parentNode.nextElementSibling,null===o&&(this.table.addRowBelow(),o=n.parentNode.nextElementSibling),o=o.firstElementChild),null!==o)if(this.utils.isEmpty(o.innerHTML))this.caret.end(o);else{var l=document.createRange();l.selectNodeContents(o),t.removeAllRanges(),t.addRange(l)}return e.originalEvent.preventDefault(),!1}}return r.call(this,e,i)}.bind(this);var l=this.keydown.formatEmpty;this.keydown.formatEmpty=function(e){for(var t,i=this.$editor[0],n=0,o=i.childElementCount;n<o;n++)if(t=i.children[n],"P"!==t.nodeName&&this.utils.isBlockTag(t.nodeName))return;return l.call(this,e)}.bind(this);var s=this.keydown.removeInvisibleSpace;this.keydown.removeInvisibleSpace=function(){this.keydown.current!==this.$editor[0]&&s.call(this)}.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(e){-1===t.indexOf(e)&&t.push(e)},_getBlocks:function(){for(var e=[this.keydown.blockquote,this.keydown.pre,this.keydown.figcaption],i=0,n=t.length;i<n;i++)e.push(this.utils.isTag(this.keydown.current,t[i]));return e},_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(n)if("TD"===n.nodeName){var o=n.innerHTML;""===o?t.preventDefault():""===o&&(t.preventDefault(),n.innerHTML="")}else 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)&&-1!==i.nodeName.indexOf("-")){var r=window.getSelection().getRangeAt(0),l=document.createRange();l.setStartBefore(n),l.setEnd(r.startContainer,r.startOffset);var s=l.cloneContents(),a=elCreate("div");if(a.appendChild(s),e(a)){t.preventDefault();var d=n.previousElementSibling,h=null;if(d)h=e(d);else for(i=n;(i=i.parentNode)&&i!==this.$editor[0];)if(d=i.previousElementSibling){h=!1;break}if(h)elRemove(d);else if(null!==h){var c=n.parentNode;if("P"===d.nodeName){d.appendChild(this.marker.get());for(var f;n.childNodes.length;){if(f=n.childNodes[0],"BR"===f.nodeName){elRemove(f);break}d.appendChild(f)}0===n.childNodes.length&&elRemove(n),this.selection.restore()}else d.appendChild(n),n.insertBefore(this.marker.get(),n.firstChild),this.selection.restore();e(c)&&elRemove(c)}else null===h&&(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)&&-1!==i.nodeName.indexOf("-")){var o=window.getSelection().getRangeAt(0),r=document.createRange();r.setStart(o.startContainer,o.startOffset),r.setEndAfter(n);var l=r.cloneContents(),s=elCreate("div");if(s.appendChild(l),e(s)){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),n=function(){return this.opts.blockTags.filter(function(e){return-1!==e.indexOf("-")}).join(",")}.bind(this),o=[],r=function(){elBySelAll(n(),this.core.editor()[0],function(e){null!==e.parentNode&&-1!==o.indexOf(e)&&["nextElementSibling","previousElementSibling"].forEach(function(t){for(var i,n=e[t];null!==n&&n.nodeName===e.nodeName&&-1===o.indexOf(n);){if("previousElementSibling"===t)for(var r=n.childNodes.length-1;r>=0;r--)e.insertBefore(n.childNodes[r],e.firstChild);else for(;n.childNodes.length>0;)e.appendChild(n.childNodes[0]);i=n[t],elRemove(n),n=i}})}),o=[]}.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):e.which!==this.keyCode.BACKSPACE&&e.which!==this.keyCode.DELETE||elBySelAll(n(),this.core.editor()[0],function(e){o.push(e)}));var l=!1;if(e.which===this.keyCode.BACKSPACE&&this.selection.isCollapsed()&&this.detect.isWebkit()){var s=this.selection.block();!1!==s&&"PRE"===s.nodeName&&(l=!0)}setTimeout($.proxy(function(){var t;if(o.length>0&&r(),l){var i=this.selection.block();if((!1===i||"PRE"!==i.nodeName)&&(t=this.selection.current(),t.nodeType===Node.TEXT_NODE&&t.nextSibling&&"SPAN"===t.nextSibling.nodeName)){var n=t.nextSibling;if(-1!==n.style.getPropertyValue("font-family").indexOf("monospace")&&"pre-wrap"===n.style.getPropertyValue("white-space")){for(;n.childNodes.length;)n.parentNode.insertBefore(n.childNodes[0],n);elRemove(n)}}}this.code.syncFire=!1,this.keydown.removeEmptyLists();var s="";0!==this.opts.keepStyleAttr.length&&(s=","+this.opts.keepStyleAttr.join(",")),this.core.editor().find("*[style]").not("span, img, figure, iframe, #redactor-image-box, #redactor-image-editter, [data-redactor-style-cache], [data-redactor-span]"+s).removeAttr("style"),this.keydown.formatEmpty(e),t=this.selection.current(),"KBD"===t.nodeName&&0===t.innerHTML.length&&elRemove(t),this.code.syncFire=!0},this),1)}.bind(this)}}}; })(this);
// plugins/WoltLabKeyup.js
(function (window, undefined) { $.Redactor.prototype.WoltLabKeyup=function(){"use strict";return{init:function(){this.WoltLabEvent.register("keyup",function(e){e.event.originalEvent.which===this.keyCode.ENTER&&this.WoltLabKeyup._keyupEnter()}.bind(this))},_keyupEnter:function(){var e=this.$editor[0],t=window.getSelection(),r=null;if(this.detect.isFirefox()){var n=t.anchorNode;if(n.nodeType===Node.TEXT_NODE&&0===t.anchorOffset&&(r=n.parentNode,r.childNodes[0]===n&&(n=n.parentNode)),"LI"===n.nodeName){var i=n.parentNode;if(r=i.parentNode,"LI"===r.nodeName&&null===i.previousSibling)return r.insertBefore(this.marker.get(),i),r.insertBefore(elCreate("br"),i),void this.selection.restore()}}for(var o=t.anchorNode;o.parentNode;){if(o.parentNode===e){r=o;break}o=o.parentNode}null!==r&&"P"===r.nodeName&&(this.WoltLabKeyup._rebuildEmptyParagraph(r,!1),null!==(r=r.previousElementSibling)&&"P"===r.nodeName&&this.WoltLabKeyup._rebuildEmptyParagraph(r,!0))},_rebuildEmptyParagraph:function(e,t){if(!(e.textContent.replace(/\u200B/g,"").trim().length>0)){for(var r=e;r.nodeType===Node.ELEMENT_NODE&&0!==r.childNodes.length;){if(r.children.length>1)return;r=1===r.children.length?r.children[0]:r.childNodes[0]}if(r.nodeType===Node.TEXT_NODE){var n=elCreate("br");r.parentNode.appendChild(n),t&&elRemove(r)}}}}}; })(this);