// table.js
if(!RedactorPlugins)var RedactorPlugins={};RedactorPlugins.table=function(){return{getTemplate:function(){return String()+'<section id="redactor-modal-table-insert"><label>'+this.lang.get("rows")+'</label><input type="text" size="5" value="2" id="redactor-table-rows" /><label>'+this.lang.get("columns")+'</label><input type="text" size="5" value="3" id="redactor-table-columns" /></section>'},init:function(){var t={};t.insert_table={title:this.lang.get("insert_table"),func:this.table.show},t.insert_row_above={title:this.lang.get("insert_row_above"),func:this.table.addRowAbove},t.insert_row_below={title:this.lang.get("insert_row_below"),func:this.table.addRowBelow},t.insert_column_left={title:this.lang.get("insert_column_left"),func:this.table.addColumnLeft},t.insert_column_right={title:this.lang.get("insert_column_right"),func:this.table.addColumnRight},t.add_head={title:this.lang.get("add_head"),func:this.table.addHead},t.delete_head={title:this.lang.get("delete_head"),func:this.table.deleteHead},t.delete_column={title:this.lang.get("delete_column"),func:this.table.deleteColumn},t.delete_row={title:this.lang.get("delete_row"),func:this.table.deleteRow},t.delete_table={title:this.lang.get("delete_table"),func:this.table.deleteTable},this.observe.addButton("td","table"),this.observe.addButton("th","table");var e=this.button.addBefore("link","table",this.lang.get("table"));this.button.addDropdown(e,t)},show:function(){this.modal.addTemplate("table",this.table.getTemplate()),this.modal.load("table",this.lang.get("insert_table"),300),this.modal.createCancelButton();var t=this.modal.createActionButton(this.lang.get("insert"));t.on("click",this.table.insert),this.selection.save(),this.modal.show(),$("#redactor-table-rows").focus()},insert:function(){var t,e,i,a,s=$("#redactor-table-rows").val(),l=$("#redactor-table-columns").val(),n=$("<div>"),r=Math.floor(99999*Math.random()),o=$('<table id="table'+r+'"><tbody></tbody></table>');for(t=0;s>t;t++){for(e=$("<tr>"),i=0;l>i;i++)a=$("<td>"+this.opts.invisibleSpace+"</td>"),0===t&&0===i&&a.append(this.selection.getMarker()),$(e).append(a);o.append(e)}n.append(o);var d=n.html();if(this.modal.close(),this.selection.restore(),!this.table.getTable()){this.buffer.set();var h=this.selection.getBlock()||this.selection.getCurrent();h&&"BODY"!=h.tagName?("LI"==h.tagName&&(h=$(h).closest("ul, ol")),$(h).after(d)):this.insert.html(d),this.selection.restore();var c=this.$editor.find("#table"+r);if(!this.opts.linebreaks&&(this.utils.browser("mozilla")||this.utils.browser("msie"))){var b=c.next();0===b.length&&c.after(this.opts.emptyHtml)}this.observe.buttons(),c.find("span.redactor-selection-marker").remove(),c.removeAttr("id"),this.code.sync(),this.core.setCallback("insertedTable",c)}},getTable:function(){var t=$(this.selection.getParent()).closest("table");return this.utils.isRedactorParent(t)?0===t.size()?!1:t:!1},restoreAfterDelete:function(t){this.selection.restore(),t.find("span.redactor-selection-marker").remove(),this.code.sync()},deleteTable:function(){var t=this.table.getTable();if(t){this.buffer.set();var e=t.next();this.opts.linebreaks||0===e.length?this.caret.setAfter(t):this.caret.setStart(e),t.remove(),this.code.sync()}},deleteRow:function(){var t=this.table.getTable();if(t){var e=$(this.selection.getCurrent());this.buffer.set();var i=e.closest("tr"),a=i.prev().length?i.prev():i.next();if(a.length){var s=a.children("td, th").first();s.length&&s.prepend(this.selection.getMarker())}i.remove(),this.table.restoreAfterDelete(t)}},deleteColumn:function(){var t=this.table.getTable();if(t){this.buffer.set();var e=$(this.selection.getCurrent()),i=e.closest("td, th"),a=i[0].cellIndex;t.find("tr").each($.proxy(function(t,e){var i=$(e),s=0>a-1?a+1:a-1;0===t&&i.find("td, th").eq(s).prepend(this.selection.getMarker()),i.find("td, th").eq(a).remove()},this)),this.table.restoreAfterDelete(t)}},addHead:function(){var t=this.table.getTable();if(t){if(this.buffer.set(),0!==t.find("thead").size())return void this.table.deleteHead();var e=t.find("tr").first().clone();e.find("td").html(this.opts.invisibleSpace),$thead=$("<thead></thead>").append(e),t.prepend($thead),this.code.sync()}},deleteHead:function(){var t=this.table.getTable();if(t){var e=t.find("thead");0!==e.size()&&(this.buffer.set(),e.remove(),this.code.sync())}},addRowAbove:function(){this.table.addRow("before")},addRowBelow:function(){this.table.addRow("after")},addColumnLeft:function(){this.table.addColumn("before")},addColumnRight:function(){this.table.addColumn("after")},addRow:function(t){var e=this.table.getTable();if(e){this.buffer.set();var i=$(this.selection.getCurrent()),a=i.closest("tr"),s=a.clone();s.find("th").replaceWith(function(){var t=$("<td>");return t[0].attributes=this.attributes,t.append($(this).contents())}),s.find("td").html(this.opts.invisibleSpace),"after"==t?a.after(s):a.before(s),this.code.sync()}},addColumn:function(t){var e=this.table.getTable();if(e){var i=0,a=$(this.selection.getCurrent());this.buffer.set();var s=a.closest("tr"),l=a.closest("td, th");s.find("td, th").each($.proxy(function(t,e){$(e)[0]===l[0]&&(i=t)},this)),e.find("tr").each($.proxy(function(e,a){var s=$(a).find("td, th").eq(i),l=s.clone();l.html(this.opts.invisibleSpace),"after"==t?s.after(l):s.before(l)},this)),this.code.sync()}}}};
// wbbcode.js
-if(!RedactorPlugins)var RedactorPlugins={};RedactorPlugins.wbbcode=function(){"use strict";var e=!1;return{init:function(){var t=this.$textarea.wcfIdentify();this.opts.initCallback=function(){window.addEventListener("unload",function(){this.code.startSync(),this.$textarea.val(this.wbbcode.convertFromHtml(this.$textarea.val()))}.bind(this)),$.browser.msie&&this.$editor.addClass("msie"),this.$textarea[0].setAttribute("data-is-dirty",!0);var e=$.trim(this.wutil.getOption("woltlab.originalValue"));e.length&&(this.wutil.replaceText(e),this.wutil.selectionEndOfEditor()),delete this.opts.woltlab.originalValue,$(document).trigger("resize"),this.wutil.saveSelection();var t=this.$editor[0],i=this.$textarea[0];setTimeout(function(){$.browser.iOS&&0===t.scrollHeight&&(document.activeElement===t||document.activeElement===i)&&document.activeElement.blur()},10)}.bind(this),this.opts.pasteBeforeCallback=$.proxy(this.wbbcode._pasteBeforeCallback,this),this.opts.pasteCallback=$.proxy(this.wbbcode._pasteCallback,this);var i=this.clean.onSync;this.clean.onSync=function(t){return t=t.replace(/\u200C/g,"__wcf_zwnj__"),t=t.replace(/\u200D/g,"__wcf_zwj__"),e===!0?e=!1:t=t.replace(/<p><br([^>]+)?><\/p>/g,"<p>@@@wcf_empty_line@@@</p>"),t=i.call(this,t),t=t.replace(/__wcf_zwnj__/g,""),t.replace(/__wcf_zwj__/g,"")}.bind(this),this.wutil.getOption("woltlab.autosaveOnce")&&(this.wutil.saveTextToStorage(),delete this.opts.woltlab.autosaveOnce);var a=this.button.get("table");if(a.length){var r=a.data("dropdown");r.find(".redactor-dropdown-add_head").parent().remove(),r.find(".redactor-dropdown-delete_head").parent().remove(),$('<li class="dropdownDivider" />').insertBefore(r.find(".redactor-dropdown-delete_table").parent()),a.click($.proxy(this.wbbcode._tableButtonClick,this))}WCF.System.Event.addListener("com.woltlab.wcf.redactor","insertBBCode_quote_"+t,$.proxy(function(e){e.cancel=!0,this.wbbcode._handleInsertQuote()},this)),WCF.System.Event.addListener("com.woltlab.wcf.redactor","insertBBCode_code_"+t,$.proxy(function(e){e.cancel=!0,this.wbbcode._handleInsertCode(null,!0)},this)),WCF.System.Event.addListener("com.woltlab.wcf.redactor","keydown_"+t,$.proxy(this.wbbcode._keydownCallback,this)),WCF.System.Event.addListener("com.woltlab.wcf.redactor","keyup_"+t,$.proxy(this.wbbcode._keyupCallback,this)),this.code.sync=function(){};var n=$(".redactor-toolbar-tooltip-html:not(.jsWbbcode)").addClass("jsWbbcode").text(WCF.Language.get("wcf.bbcode.button.toggleBBCode")),l=function(e){e.find("br").each(function(e,t){t.children.length&&$(t).empty()})};this.code.toggle=function(){if(this.opts.visual)this.code.startSync(),this.code.showCode(),this.$textarea.val(this.wbbcode.convertFromHtml(this.$textarea.val())),this.button.get("html").children("i").removeClass("fa-square-o").addClass("fa-square"),n.text(WCF.Language.get("wcf.bbcode.button.toggleHTML"));else{if(this.$textarea.val(this.wbbcode.convertToHtml(this.$textarea.val())),this.code.offset=this.$textarea.val().length,this.code.showVisual(),this.wutil.fixDOM(),this.wbbcode.fixBlockLevelElements(),this.wutil.selectionEndOfEditor(),this.wbbcode.observeQuotes(),this.wbbcode.observeCodeListings(),this.button.get("html").children("i").removeClass("fa-square").addClass("fa-square-o"),n.text(WCF.Language.get("wcf.bbcode.button.toggleBBCode")),this.wutil.fixDOM(),l(this.$editor),/ Edge\//.test(navigator.userAgent)){var e=this.$editor[0];window.dtdesign=e,e.childElementCount>1&&""===e.children[0].innerHTML&&e.removeChild(e.children[0])}this.wutil.saveSelection()}}.bind(this),this.wutil.setOption("clickCallback",function(e){e.target===this.$editor[0]&&this.$editor[0].lastElementChild&&"BLOCKQUOTE"===this.$editor[0].lastElementChild.tagName&&this.wutil.setCaretAfter($(this.$editor[0].lastElementChild)),setTimeout(this.wutil.saveSelection.bind(this),10)}.bind(this));var o=this.opts.verifiedTags.indexOf("ul");o>-1&&this.opts.verifiedTags.splice(o,1),WCF.System.Event.addListener("com.woltlab.wcf.redactor","observe_load_"+t,function(){this.wbbcode.observeCodeListings(),this.wbbcode.observeQuotes()}.bind(this)),WCF.System.Event.addListener("com.woltlab.wcf.redactor","fixFormatting_"+t,$.proxy(this.wbbcode.fixFormatting,this))},_tableButtonClick:function(e){var t=$(e.currentTarget);if(t.hasClass("dropact")){var i=this.selection.getBlock()||this.selection.getCurrent(),a=t.data("dropdown");a.children("li").show();var r=a.find("> li > .redactor-dropdown-insert_table").parent();"TD"==i.tagName?r.hide():r.nextAll().hide()}},insertSmiley:function(e,t,i){function a(e){return null===e?!1:(e.nodeType===Node.ELEMENT_NODE&&"SPAN"===e.nodeName||e.nodeType===Node.TEXT_NODE)&&" "===e.textContent?!0:!1}if(i&&this.wbbcode.registerSmiley(e,t),this.opts.visual){this.wutil.restoreSelection();var r=window.getSelection();r.rangeCount||this.focus.setEnd();var n=r.getRangeAt(0);n.deleteContents();var l=document.createElement("img");l.src=t,l.className="smiley",l.alt=e,n.insertNode(l);var o=l,c=l.parentElement;if(!a(l.previousSibling)){var s=document.createTextNode(" ");c.insertBefore(s,l)}if(!a(l.nextSibling)){var s=document.createTextNode(" ");c.lastChild===l?c.appendChild(s):c.insertBefore(s,l.nextSibling),o=s}var n=document.createRange();n.selectNode(o),n.collapse(!1),r.removeAllRanges(),r.addRange(n),this.wutil.saveSelection()}else this.wutil.insertAtCaret(" "+e+" ")},registerSmiley:function(e,t){return __REDACTOR_SMILIES[e]?!1:(__REDACTOR_SMILIES[e]=t,!0)},convertFromHtml:function(e){var t=[];WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","beforeConvertFromHtml",{html:e}),e=e.replace(/(<[^>]+?) data-redactor-tag="[^"]+"/g,"$1"),e=e.replace(/(<[^>]+?) rel="[^"]+"/g,"$1"),e=e.replace(/&#(8203|x200b);/g,""),e=e.replace(/™/gi,"™"),e=e.replace(/©/gi,"©"),e=e.replace(/…/gi,"…"),e=e.replace(/—/gi,"—"),e=e.replace(/‐/gi,"‐");var i={};e=e.replace(/<div([^>]+?)class="codeBox[^"]+"([^>]*?)>\n*<div>[\s\S]+?<ol start="(\d+)">([\s\S]+?)<\/ol>\n*<\/div>\n*<\/div>/g,function(e,t,a,r,n){var l=t+" "+a,o="",c="";l.match(/data-highlighter="([a-zA-Z]+)"/)&&(o=RegExp.$1),l.match(/data-filename="([^"]+)"/)&&(c=$.trim(RegExp.$1));var s=WCF.getUUID();return i[s]={codeContent:n.replace(/<li>/g,"").replace(/<\/li>/g,"\n").replace(/\n$/,""),filename:c.replace(/['"]/g,""),highlighter:"plain"===o?"":o,lineNumber:r>1?r:0},"@@@"+s+"@@@"}),e=e.replace(/\r?\n/g,""),e=e.replace(/<a[^>]*?><\/a>/g,""),e=e.replace(/<p><\/p><table/g,"<table"),e=e.replace(/<\/table><p><\/p>/g,"</table>");for(var a in i)e=e.replace(new RegExp("<p></p>@@@"+a+"@@@<p></p>"),"@@@"+a+"@@@");e=e.replace(/<p><\/p><p>(?!<br>)/g,"<p>@@@wcf_empty_line@@@</p><p>"),e=e.replace(/<br( \/)?><\/p>/g,"</p>");for(var r=e.split(/(<\/?(?:div|p)>)/),n="",l="",o=0;o<r.length;o++){var c=r[o];"<p>"!=c&&"<div>"!=c&&("</p>"==c||"</div>"==c?(l=$.trim(l),"@@@wcf_empty_line@@@"!=l&&(l+="\n"),n+=l,l=""):0==o||o+1==r.length?n+=c:l+=c)}l&&(n+=l,l=""),e=n,e=e.replace(/@@@wcf_empty_line@@@/g,"\n"),e=e.replace(/\n\n$/,"\n"),e=e.replace(/<br>$/,""),e=e.replace(/<br>/g,"\n"),e=e.replace(/<br>/g,""),e=e.replace(/ /gi," "),e=e.replace(/<blockquote([^>]+)>\n?<header[^>]*?>[\s\S]*?<\/header>/gi,function(e,t){var i,a="",r="";return t.match(/data-author="([^"]+)"/)&&(a=WCF.String.unescapeHTML(RegExp.$1)),t.match(/cite="([^"]+)"/)&&(r=WCF.String.unescapeHTML(RegExp.$1)),i=r?"[quote='"+a+"','"+r+"']":a?"[quote='"+a+"']":"[quote]"}),e=e.replace(/(?:\n*)<\/blockquote>\n?/gi,"\n[/quote]\n"),e=e.replace(/<a [^>]*?href=(["'])mailto:(.+?)\1.*?>([\s\S]+?)<\/a>/gi,"[email=$2]$3[/email]"),e=e.replace(/<a[^>]+><\/a>/,""),e=e.replace(/<a [^>]*?href=(["'])(.+?)\1.*?>([\s\S]+?)<\/a>/gi,function(e,t,i,a){return i==a?"[url]"+i+"[/url]":"[url='"+i+"']"+a+"[/url]"}),e=e.replace(/<(?:b|strong)>/gi,function(){return-1===t.indexOf("b")&&t.push("b"),"[b]"}),e=e.replace(/<\/(?:b|strong)>/gi,"[/b]"),e=e.replace(/<(?:i|em)>/gi,function(){return-1===t.indexOf("i")&&t.push("i"),"[i]"}),e=e.replace(/<\/(?:i|em)>/gi,"[/i]"),e=e.replace(/<u>/gi,function(){return-1===t.indexOf("u")&&t.push("u"),"[u]"}),e=e.replace(/<\/u>/gi,"[/u]"),e=e.replace(/<sub>/gi,function(){return-1===t.indexOf("sub")&&t.push("sub"),"[sub]"}),e=e.replace(/<\/sub>/gi,"[/sub]"),e=e.replace(/<sup>/gi,function(){return-1===t.indexOf("sup")&&t.push("sup"),"[sup]"}),e=e.replace(/<\/sup>/gi,"[/sup]"),e=e.replace(/<(?:s(trike)?|del)>/gi,function(){return-1===t.indexOf("s")&&t.push("s"),"[s]"}),e=e.replace(/<\/(?:s(trike)?|del)>/gi,"[/s]");for(var s=e.split(/(<\/?span[^>]*>)/),l=[],d=[],h="",p={11:8,13:10,16:12,19:14,24:18,29:22,32:24,48:36},o=0;o<s.length;o++){var g=s[o];if("</span>"==g){var u=d.pop(),n=u.start+l.pop()+u.end;l.length?l[l.length-1]+=n:h+=n}else if(g.match(/^<span/))if(g.match(/^<span(?:.*?)style="([^"]+)"(?:[^>]*?)>/)){var f,m,b=RegExp.$1;if(b.match(/(?:^|;\s*)color: ?rgb\((\d{1,3}), ?(\d{1,3}), ?(\d{1,3})\);?/i)){var v=RegExp.$1,w=RegExp.$2,x=RegExp.$3,C="0123456789ABCDEF".charAt((v-v%16)/16)+""+"0123456789ABCDEF".charAt(v%16)+("0123456789ABCDEF".charAt((w-w%16)/16)+""+"0123456789ABCDEF".charAt(w%16))+("0123456789ABCDEF".charAt((x-x%16)/16)+""+"0123456789ABCDEF".charAt(x%16));f="[color=#"+C+"]",m="[/color=#"+C+"]",-1===t.indexOf("color")&&t.push("color")}else b.match(/(?:^|;\s*)color: ?([^;]+);?/i)?(f="[color="+RegExp.$1+"]",m="[/color="+RegExp.$1+"]",-1===t.indexOf("color")&&t.push("color")):b.match(/font-size: ?(\d+)(pt|px);?/i)?"pt"==RegExp.$2?(f="[size="+RegExp.$1+"]",m="[/size="+RegExp.$1+"]",-1===t.indexOf("size")&&t.push("size")):p[RegExp.$1]?(f="[size="+p[RegExp.$1]+"]",m="[/size="+p[RegExp.$1]+"]",-1===t.indexOf("size")&&t.push("size")):(f="",m=""):b.match(/font-family: ?([^;]+);?/)?(f="[font='"+RegExp.$1.replace(/'/g,"")+"']",m="[/font='"+RegExp.$1.replace(/'/g,"")+"']",-1===t.indexOf("font")&&t.push("font")):(f='<span style="'+b+'">',m="</span>");l[l.length]="",d[l.length]={start:f,end:m}}else g.match(/^<span class="inlineCode">/)?(l[l.length]="",d[l.length]={start:"[tt]",end:"[/tt]"}):(l[l.length]="",d[l.length]={start:"",end:""});else l.length?l[l.length-1]+=g:h+=g}if(e=h,e=e.replace(/<(div|p) style="text-align: ?(left|center|right|justify);? ?">([\s\S]*?)\n/gi,function(e,i,a,r){return-1===t.indexOf("align")&&t.push("align"),"[align="+a+"]"+$.trim(r)+"[/align="+a+"]\n"}),t.length){for(var E=!0;E;)E=!1,e=e.replace(new RegExp("\\[\\/((?:"+t.join("|")+")=[^\\]]+?)\\]\n\\[\\1\\]","gi"),function(){return E=!0,"\n"});e=e.replace(new RegExp("\\[\\/("+t.join("|")+")=[^\\]]+?\\]","gi"),"[/$1]")}e=e.replace(/ ?<img [^>]*?alt="([^"]+?)"[^>]*?class="smiley"[^>]*?> ?/gi," $1 "),e=e.replace(/ ?<img [^>]*?class="smiley"[^>]*?alt="([^"]+?)"[^>]*?> ?/gi," $1 "),e=e.replace(/<img([^>]*?)class="[^"]*redactorEmbeddedAttachment[^"]*"([^>]*?)>/gi,function(e,t,i){var a,r=t+" "+i;if(!r.match(/data-attachment-id="(\d+)"/))return e;a=RegExp.$1;var n="none",l=null;if(r.match(/style="([^"]+)"/)){for(var o=RegExp.$1.split(";"),c=0;c<o.length;c++){var s=$.trim(o[c]);s.match(/^float: (left|right)$/)?n=RegExp.$1:s.match(/^width: (\d+)px$/)&&(l=RegExp.$1)}if(null!==l)return"[attach="+a+","+n+","+l+"][/attach]";if("none"!==n)return"[attach="+a+","+n+"][/attach]"}return"[attach="+a+"][/attach]"}),e=e.replace(/<img([^>]*)?src=(["'])([^"']+?)\2([^>]*)?>/gi,function(e,t,i,a,r){var n=t+" "+r,l="";n.match(/style="([^"]+)"/)&&(l=RegExp.$1);for(var o="none",c=0,s=l.split(";"),d=0;d<s.length;d++){var h=s[d];h.match(/float: (left|right|none)/)?o=RegExp.$1:h.match(/width: (\d+)px/)&&(c=parseInt(RegExp.$1))}return c?"[img='"+a+"',"+o+","+c+"][/img]":"none"!==o?"[img='"+a+"',"+o+"][/img]":"[img]"+a+"[/img]"}),e=e.replace(/<li>/gi,"[*]"),e=e.replace(/<\/li>/gi,"\n"),e=e.replace(/<ul>/gi,"[list]"),e=e.replace(/<(ol|ul style="list-style-type: decimal")>/gi,"[list=1]"),e=e.replace(/<ul style="list-style-type: (none|circle|square|disc|decimal|lower-roman|upper-roman|decimal-leading-zero|lower-greek|lower-latin|upper-latin|armenian|georgian)">/gi,"[list=$1]"),e=e.replace(/<\/(ul|ol)>/gi,"[/list]"),e=e.replace(/\n?\[list\]/g,"\n[list]"),e=e.replace(/\[\/list\]\n\[\*\]/g,"[/list][*]"),e=e.replace(/\[\/list\]\n\[\/list\]/g,"[/list][/list]"),e=e.replace(/<table[^>]*>/gi,"[table]\n"),e=e.replace(/<\/table>\n?/gi,"[/table]\n"),e=e.replace(/<tbody>([\s\S]*?)<\/tbody>/,function(e,t){return $.trim(t)}),e=e.replace(/<tr><\/tr>/gi,""),e=e.replace(/<tr>/gi,"[tr]\n"),e=e.replace(/<\/tr>/gi,"[/tr]\n"),e=e.replace(/<td style="text-align: ?(left|center|right|justify);? ?">([\s\S]*?)<\/td>/gi,"[td][align=$1]$2[/align][/td]"),e=e.replace(/(\t)*<td>(\t)*/gi,"[td]"),e=e.replace(/(\t)*<\/td>/gi,"[/td]\n");var y={};if(e.replace(/<span id="selection-marker-\d+" class="redactor-selection-marker"><\/span>/,function(e){var t=e.hashCode();return y[t]=e.replace(/\$/g,"$$$$"),"@@"+t+"@@"}),WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","convertFromHtml",{html:e}),e=e.replace(/<[^(<|>)]+>/g,""),$.getLength(y))for(var S in y){var _=new RegExp("@@"+S+"@@","g");e=e.replace(_,y[S])}return $.getLength(i)&&$.each(i,function(t,i){var a=0;i.highlighter&&a++,i.lineNumber&&a++,i.filename&&a++;var r="";switch(a){case 1:r=i.highlighter?i.highlighter:i.filename?"'"+i.filename+"'":i.lineNumber;break;case 2:i.lineNumber&&(r=i.lineNumber),i.highlighter&&(r.length&&(r+=","),r+=i.highlighter),i.filename&&(r.length&&(r+=","),r+="'"+i.filename+"'");break;case 3:r=i.highlighter+","+i.lineNumber+",'"+i.filename+"'"}var n="[code"+(r.length?"="+r:"")+"]"+i.codeContent+"[/code]\n";e=e.replace(new RegExp("@@@"+t+"@@@\n?","g"),n.replace(/\$/g,"$$$"))}),e=e.replace(/</g,"<"),e=e.replace(/>/g,">"),e=e.replace(/&/g,"&"),e=e.replace(/%28/g,"("),e=e.replace(/%29/g,")"),WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","afterConvertFromHtml",{html:e}),e=$.trim(e),e.length&&(e+="\n"),e},convertToHtml:function(e){WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","beforeConvertToHtml",{data:e}),e=this.wutil.removeZeroWidthSpace(e),e=e.replace(/&/g,"&"),e=e.replace(/</g,"<"),e=e.replace(/>/g,">");var t=[],i=new RegExp("\\[("+__REDACTOR_SOURCE_BBCODES.join("|")+")([\\S\\s]+?)\\[\\/\\1\\]","gi");e=e.replace(i,function(e){var i=e.hashCode();return t.push({key:i,value:e.replace(/\$/g,"$$$$")}),"@@"+i+"@@"}),e=e.replace(/\[url\]([^"]+?)\[\/url]/gi,'<a href="$1">$1</a>'+this.opts.invisibleSpace),e=e.replace(/\[url\='([^'"]+)']([\s\S]+?)\[\/url]/gi,'<a href="$1">$2</a>'+this.opts.invisibleSpace),e=e.replace(/\[url\=([^'"\]]+)]([\s\S]+?)\[\/url]/gi,'<a href="$1">$2</a>'+this.opts.invisibleSpace),e=e.replace(/\[email\]([^"]+?)\[\/email]/gi,'<a href="mailto:$1">$1</a>'+this.opts.invisibleSpace),e=e.replace(/\[email\=([^"\]]+)](.+?)\[\/email]/gi,'<a href="mailto:$1">$2</a>'+this.opts.invisibleSpace),e=e.replace(/\[(b|i|s|sub|sup|u)\]\[\1\]/gi,"[$1]"),e=e.replace(/\[(\/(?:b|i|s|sub|sup|u))\]\[\1\]/gi,"[$1]"),e=e.replace(/\[(b|i|s|sub|sup|u)\]\[\/\1\]/gi,""),e=e.replace(/\[b\]([\s\S]*?)\[\/b]/gi,function(e,t){return this.wbbcode._expandFormatting(t,"<strong>","</strong>")}.bind(this)),e=e.replace(/\[i\]([\s\S]*?)\[\/i]/gi,function(e,t){return this.wbbcode._expandFormatting(t,"<em>","</em>")}.bind(this)),e=e.replace(/\[u\]([\s\S]*?)\[\/u]/gi,function(e,t){return this.wbbcode._expandFormatting(t,"<u>","</u>")}.bind(this)),e=e.replace(/\[s\]([\s\S]*?)\[\/s]/gi,function(e,t){return this.wbbcode._expandFormatting(t,"<del>","</del>")}.bind(this)),e=e.replace(/\[sub\]([\s\S]*?)\[\/sub]/gi,function(e,t){return this.wbbcode._expandFormatting(t,"<sub>","</sub>")}.bind(this)),e=e.replace(/\[sup\]([\s\S]*?)\[\/sup]/gi,function(e,t){return this.wbbcode._expandFormatting(t,"<sup>","</sup>")}.bind(this)),e=e.replace(/\[img\]([^"]+?)\[\/img\]/gi,'<img src="$1" />'),e=e.replace(/\[img='?([^"]*?)'?,'?(left|right)'?\]\[\/img\]/gi,function(e,t,i){var a="float: "+i+";";return a+="left"===i?"margin: 0 15px 7px 0":"margin: 0 0 7px 15px",'<img src="'+t+'" style="'+a+'" />'}),e=e.replace(/\[img='?([^"]*?)'?,'?(left|right|none)'?,'?(\d+)'?\]\[\/img\]/gi,function(e,t,i,a){var r="float: "+i+"; width: "+a+"px;";return r+="left"===i?"margin: 0 15px 7px 0":"margin: 0 0 7px 15px",'<img src="'+t+'" style="'+r+'" />'}),e=e.replace(/\[img='?([^"]*?)'?\]\[\/img\]/gi,'<img src="$1" />'),e=e.replace(/\[size=(\d+)\]([\s\S]*?)\[\/size\]/gi,function(e,t,i){return this.wbbcode._expandFormatting(i,'<span style="font-size: '+t+'pt">',"</span>")}.bind(this)),e=e.replace(/\[color=([#a-z0-9]*?)\]([\s\S]*?)\[\/color\]/gi,function(e,t,i){return this.wbbcode._expandFormatting(i,'<span style="color: '+t+'">',"</span>")}.bind(this)),e=e.replace(/\[font='?([a-z,\- ]*?)'?\]([\s\S]*?)\[\/font\]/gi,function(e,t,i){return this.wbbcode._expandFormatting(i,'<span style="font-family: '+t+'">',"</span>")}.bind(this)),e=e.replace(/\[align=(left|right|center|justify)\]([\s\S]*?)\[\/align\]/gi,function(e,t,i){return this.wbbcode._expandFormatting(i,'<p style="text-align: '+t+'">',"</p>")}.bind(this));var a=e.indexOf("[list");if(a>0){var r=e.substr(0,a);r=r.replace(/\[\*\]/g,""),e=r+e.substr(a)}var n=e.lastIndexOf("[/list]");if(-1===n)e=e.replace(/\[\*\]/g,""),e=e.replace(/\[list[^\]]*\]/g,"");else{var r=e.substr(n+7);r=r.replace(/\[\*\]/g,""),e=e.substr(0,n+7)+r}e=e.replace(/\[\*\]([\s\S]*?)(?=\[\*\]|\[\/list\])/gi,function(e,t){return"<li>"+$.trim(t)+"</li>"}),e=e.replace(/\n*(\[list\]<\/li>)/g,"$1"),e=e.replace(/\[list\]/gi,"<ul>"),e=e.replace(/\[list=1\]/gi,'<ul style="list-style-type: decimal">'),e=e.replace(/\[list=a\]/gi,'<ul style="list-style-type: lower-latin">'),e=e.replace(/\[list=(none|circle|square|disc|decimal|lower-roman|upper-roman|decimal-leading-zero|lower-greek|lower-latin|upper-latin|armenian|georgian)\]/gi,'<ul style="list-style-type: $1">'),e=e.replace(/\[\/list\]/gi,"</ul>"),e=e.replace(/\[table\]([\S\s]*?)\[\/table\]/gi,function(e,t){return"[table]"+$.trim(t)+"[/table]"}),e=e.replace(/\[table\]\n*/gi,'<table border="1" cellspacing="1" cellpadding="1" style="width: 500px;">'),e=e.replace(/\[\/table\](\n*)?/gi,function(e,t){return t?(t.match(/\n/g).length>2&&(t=t.replace(/^\n/,"")),"</table>"+t):"</table>"}),e=e.replace(/\[tr\]\n*/gi,"<tr>"),e=e.replace(/\[\/tr\]\n*/gi,"</tr>"),e=e.replace(/\[td\]\n*/gi,"<td>"),e=e.replace(/\[\/td\]\n*/gi,"</td>"),e=e.replace(/<td>([\S\s]*?)<\/td>/gi,function(e,t){var i=$.trim(t);return i.length||(i="​"),"<td>"+i+"</td>"});var l=this.wutil.getOption("woltlab.attachmentUrl"),o=this.wutil.getOption("woltlab.attachmentThumbnailUrl");if(l){var c=this.wbbcode._getImageAttachments();e=e.replace(/\[attach=(\d+)\]\[\/attach\]/g,function(e,t){return t=parseInt(t),void 0!==c[t]?'<img src="'+o.replace(/987654321/,t)+'" class="redactorEmbeddedAttachment redactorDisableResize" data-attachment-id="'+t+'" />':e}),e=e.replace(/\[attach=(\d+),(left|right|none)\]\[\/attach\]/g,function(e,t,i){if(t=parseInt(t),void 0!==c[t]){var a="";return("left"===i||"right"===i)&&(a="float: "+i+";",a+="left"===i?"margin: 0 15px 7px 0":"margin: 0 0 7px 15px"),a=' style="'+a+'"','<img src="'+o.replace(/987654321/,t)+'" class="redactorEmbeddedAttachment redactorDisableResize" data-attachment-id="'+t+'"'+a+" />"}return e}),e=e.replace(/\[attach=(\d+),(left|right|none),(\d+)\]\[\/attach\]/g,function(e,t,i,a){if(t=parseInt(t),void 0!==c[t]){var r="width: "+a+"px; max-height: "+c[t].height+"px; max-width: "+c[t].width+"px;";return("left"===i||"right"===i)&&(r+="float: "+i+";",r+="left"===i?"margin: 0 15px 7px 0":"margin: 0 0 7px 15px"),r=' style="'+r+'"','<img src="'+l.replace(/987654321/,t)+'" class="redactorEmbeddedAttachment" data-attachment-id="'+t+'"'+r+" />"}return e})}for(var s in __REDACTOR_SMILIES){var d=s.replace(/</g,"<").replace(/>/g,">"),h=new RegExp("(\\s|>|^)"+WCF.String.escapeRegExp(d)+"(?=\\s|<|$)","gi");e=e.replace(h,'$1<img src="'+__REDACTOR_SMILIES[s]+'" class="smiley" alt="'+d+'" />')}e=e.replace(/(javascript):/gi,"$1<span></span>:"),e=e.replace(/(\r|\r\n)/g,"\n");for(var p=[],g=[],u=e.split(/(\[(?:\/quote|quote|quote='[^']*?'(?:,'[^']*?')?|quote="[^"]*?"(?:,"[^"]*?")?)\])/i),f=WCF.getUUID();;){for(var m=!1,b=0;b<u.length;b++){var v=u[b];if("[/quote]"===v.toLowerCase()){m=!0;for(var w="",x=u.slice(0,b),C=!1;x.length;){var E=x.pop();if(w=E+w,E.match(/^\[quote/i)){v=w+v;var y=WCF.getUUID();p.push({hashCode:y,content:v.replace(/\$/g,"$$$$")}),g.push(y),v="@@"+y+"@@",C=!0;break}}C||(x=u.slice(0,b),v=f),u=x.concat(v,u.slice(b+1));break}}if(!m)break}e=u.join(""),e=e.replace(new RegExp(f,"g"),"[/quote]"),e=e.replace(/\n*$/,"");var S=[];e=e.replace(/(<li>[\s\S]*?<\/li>)/g,function(e){e=$.trim(e).replace(/\n/g,"<br>");var t=WCF.getUUID();return S.push({key:t,content:e}),t});var r=e.split("\n");e="";for(var b=0,_=r.length;_>b;b++){var k=$.trim(r[b]);if(k.match(/^<([a-z]+)/)||k.match(/<\/([a-z]+)>$/))e+=this.reIsBlock.test(RegExp.$1.toUpperCase())||"TABLE"===RegExp.$1.toUpperCase()?k.match(/^<([a-z]+).*<\/\1>/)?k:k+"<br />":"<p>"+k+"</p>";else{if(k){if(k.match(/^@@([0-9\-]+)@@$/)&&WCF.inArray(RegExp.$1,g)){e+=k;continue}}else k="<br>";e+="<p>"+k+"</p>"}}if(e=e.replace(/<td>([\s\S]+?)<\/td>/g,function(e,t){return t=t.replace(/<br(?: \/)?>(<[uo]l)/g,"$1"),"<td>"+t.replace(/<p><br(?: \/)?><\/p>/g,"<br>").replace(/<p>/g,"").replace(/<\/p>/g,"<br>").replace(/<br>$/,"")+"</td>"}),S.length)for(var b=S.length-1;b>=0;b--)e=e.replace(S[b].key,S[b].content);if(p.length)for(var R=function(e){return e.replace(/^['"]/,"").replace(/['"]$/,"")},T=this,L=function(e){return e.replace(/\[quote(=(['"]).+?\2)?\]([\S\s]*)\[\/quote\]/gi,function(e,t,i,a){var r="",n="";if(t){switch(t=t.substr(1),t=t.split(","),t.length){case 1:r=t[0];break;case 2:r=t[0],n=t[1]}r=WCF.String.escapeHTML(R($.trim(r))),n=WCF.String.escapeHTML(R($.trim(n)))}var l='<blockquote class="quoteBox container containerPadding quoteBoxSimple" cite="'+n+'" data-author="'+r+'"><header contenteditable="false"><h3>'+T.wbbcode._buildQuoteHeader(r,n)+'</h3><a class="redactorQuoteEdit"></a></header>';a=$.trim(a);var o="";if(a.length)for(var c=a.split("\n"),s=0;s<c.length;s++){var d=c[s];if(0===d.length)d=T.opts.invisibleSpace;else if(d.match(/^@@([0-9\-]+)@@$/)&&WCF.inArray(RegExp.$1,g)){o+=d;continue}o+="<div>"+d+"</div>"}else o="<div>"+T.opts.invisibleSpace+"</div>";return l+=o,l+="</blockquote>"})},b=p.length-1;b>=0;b--){var F=p[b],A=new RegExp("@@"+F.hashCode+"@@","g");e=e.replace(A,L(F.content))}if(e=e.replace(/<(?:div|p)><(blockquote|div)/g,"<$1"),e=e.replace(/<\/(blockquote|div)><\/(?:div|p)>/g,"</$1>"),t.length)for(var b=t.length-1;b>=0;b--){var B=t[b],A=new RegExp("@@"+B.key+"@@","g"),O=B.value;O=O.replace(/^\[tt\]([\s\S]+)\[\/tt\]/,function(e,t){var i=t.split("\n");t="";for(var a=0,r=i.length;r>a;a++){var n=i[a];if(n.length)t.length&&(t+="</p><p>"),t+="[tt]"+n+"[/tt]";else{if(0===a||a+1===r)continue;t+=t.match(/\[\/tt\]$/)?"</p><p>"+this.opts.invisibleSpace:"</p><p><br>"}}return t}.bind(this)),O=O.replace(/^\[code([^\]]*)\]([\S\s]*)\[\/code\]$/,function(e,t,i){var a="plain",r=0,n="";if(t){t=t.substring(1),t=t.split(",");var l=function(e){return e.match(/^\d+$/)},o=function(e){return-1!==e.indexOf(".")||e.match(/^(["']).*\1$/)},c=function(e){return void 0!==__REDACTOR_CODE_HIGHLIGHTERS[e]},s=function(e){return e.replace(/^(["'])(.*)\1$/,"$2")};switch(t.length){case 1:l(t[0])?r=parseInt(t[0])>1?t[0]:0:o(t[0])?n=s(t[0]):c(t[0])&&(a=t[0]);break;case 2:l(t[0])?(r=parseInt(t[0])>1?t[0]:0,c(t[1])?a=t[1]:o(t[1])&&(n=s(t[1]))):(c(t[0])&&(a=t[0]),o(t[1])&&(n=s(t[1])));break;case 3:c(t[0])&&(a=t[0]),l(t[1])&&(r=t[1]),o(t[2])&&(n=s(t[2]))}}i=i.replace(/^\n+/,"").replace(/\n+$/,"").split(/\n/);for(var d="",h=0;h<i.length;h++){var p=i[h];p.length||(p=this.opts.invisibleSpace),d+="<li>"+p+"</li>"}return'<div class="codeBox container" contenteditable="false" data-highlighter="'+a+'"'+(n?' data-filename="'+WCF.String.escapeHTML(n)+'"':"")+"><div><div><h3>"+__REDACTOR_CODE_HIGHLIGHTERS[a]+(n?": "+WCF.String.escapeHTML(n):"")+'</h3></div><ol start="'+(r>1?r:1)+'">'+d+"</ol></div></div>"}.bind(this)),e=e.replace(A,O)}return WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","afterConvertToHtml",{data:e}),e},_expandFormatting:function(e,t,i){if(!e.length)return t+this.opts.invisibleSpace+i;var a=e.indexOf("[/td]");if(-1!==a){var r=e.substring(0,a);if(-1===r.indexOf("[td]"))return t+r+i+e.substring(a)}var r=e.split("\n");e="";for(var n=0,l=r.length;l>n;n++){var o=r[n];0===o.length&&(o=this.opts.invisibleSpace),e.length&&(e+="\n"),e+=t+o+i}return e},_pasteBeforeCallback:function(e){var t={1:24,2:22,3:18,4:14,5:12,6:10};return e=e.replace(/<h([1-6])([^>]*)>/g,function(e,i,a){if(a&&a.match(/style="([^"]+?)"/)&&/font-size: ?(\d+|\d+\.\d+)(px|pt|em|rem|%)/.test(RegExp.$1)){var r=$('<div style="width: '+RegExp.$1+RegExp.$2+'; position: absolute;" />').appendTo(document.body),n=parseInt(r[0].clientWidth);r.remove();var l=-1,o=!1;$.each(t,function(e,i){-1===l?l=e:Math.abs(n-i)<Math.abs(n-t[l])&&(l=e),n==i&&(o=!0)}),o||(l=6>l?parseInt(l)+1:l),i=l}return"[size="+t[i]+"]"}),e=e.replace(/<\/h[1-6]>/g,"[/size]"),(/<p class="MsoNormal/.test(e)||/margin-bottom: 0cm/.test(e))&&(console.debug("hit"),e=e.replace(/([^>\s])\n([^<\s])/g,"$1 $2"),e=e.replace(/<a name="[^"]+">/g,"")),e=e.replace(/<o:p> <\/o:p>/g,"<br>"),e=e.replace(/<(article|header)[^>]+>/g,"<div>"),e=e.replace(/<\/(article|header)>/g,"</div>"),e=e.replace(/<(div|p)([^>]+)?><(div|p)([^>]+)?>/g,"<p>"),e=e.replace(/<\/(div|p)><\/(div|p)>/g,"</p>"),e=e.replace(/<(?:div|p|span)[^>]+>/gi,function(e){return e.replace(/ class="[^"]+"/,"")}),e=e.replace(/<\/?wbr[^>]*>/g,""),WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","beforePaste",{html:e}),e},_pasteCallback:function(e){return e=e.replace(/\[size=(\d+)\]/g,'<p><span style="font-size: $1pt">'),e=e.replace(/\[\/size\]/g,"</span></p>"),e=e.replace(/style="([^"]+)"/,function(e,t){for(var i=t.split(";"),a=[],r=0,n=i.length;n>r;r++){var l=i[r];l.match(/^\s*background-color/)||a.push(l)}return'style="'+a.join(";")+'"'}),WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","afterPaste",{html:e}),e},insertAttachment:function(e,t){e=parseInt(e);var i=this.wutil.getOption("woltlab.attachment"+(t?"":"Thumbnail")+"Url"),a=this.wbbcode._getImageAttachments();if(i&&void 0!==a[e]){var r="";t&&(r=' style="width: '+a[e].width+"px; max-height: "+a[e].height+"px; max-width: "+a[e].width+'px;"'),this.wutil.insertDynamic('<img src="'+i.replace(/987654321/,e)+'" class="redactorEmbeddedAttachment'+(t?"":" redactorDisableResize")+'" data-attachment-id="'+e+'"'+r+" />","[attach="+e+(t?",none,"+a[e].width:"")+"][/attach]")}else this.wutil.insertDynamic("[attach="+e+"][/attach]")},removeAttachment:function(e){this.opts.visual&&this.$editor.find("img.redactorEmbeddedAttachment").each(function(t,i){var a=$(i);a.data("attachmentID")==e&&a.remove()})},_getImageAttachments:function(){var e=this.wutil.getOption("woltlab.attachmentImages")||[];if(e.length)return delete this.opts.attachmentImages,e;var t={imageAttachments:{}};return WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","getImageAttachments_"+this.$textarea.wcfIdentify(),t),t.imageAttachments},_keydownCallback:function(e){switch(e.event.which){case $.ui.keyCode.BACKSPACE:case $.ui.keyCode.DELETE:case $.ui.keyCode.DOWN:case $.ui.keyCode.ENTER:case $.ui.keyCode.UP:case 83:break;default:return}this.selection.get();var t=this.selection.getCurrent(),i=this.selection.getParent();i=i?$(i):i;var a=i?i.closest("blockquote.quoteBox",this.$editor.get()[0]):{length:0};switch(e.event.which){case $.ui.keyCode.BACKSPACE:if(this.wutil.isCaret()){var r=!1;if(a.length){for(var n=!0,l=0;l<a[0].children.length;l++){var o=a[0].children[l];if("DIV"===o.tagName&&o.textContent.replace(/\u200b/,"").length){n=!1;break}}if(n)r=!0;else{var c=null===this.selection.implicitRange?this.range:this.selection.implicitRange;if(0===c.startOffset)for(var s,d=c.startContainer;null!==(d=d.parentNode);)if(s=d.previousSibling,null!==s){s.nodeType===Node.ELEMENT_NODE&&"HEADER"===s.nodeName&&(r=!0);break}}}if(r){var h=window.getSelection();h.rangeCount&&h.removeAllRanges();var p=document.createRange();p.selectNode(a[0]||a),h.addRange(p),e.cancel=!0}}break;case $.ui.keyCode.DELETE:if(this.wutil.isCaret()&&this.wutil.isEndOfElement(t)){var g=t.nextElementSibling;if(g&&"BLOCKQUOTE"===g.tagName){var h=window.getSelection();h.rangeCount&&h.removeAllRanges();var p=document.createRange();p.selectNode(g),h.addRange(p),e.cancel=!0}}break;case $.ui.keyCode.DOWN:var u=$(t);if(u.next("blockquote").length)this.caret.setStart(u.next().children("div:first")),e.cancel=!0;else if(i)if(i.next("blockquote").length)this.caret.setStart(i.next().children("div:first")),e.cancel=!0;else if(a.length){var f=u.closest("div",a[0]);f.next().length||(a.next().length?this.caret.setStart(a.next()):this.wutil.setCaretAfter(a),e.cancel=!0)}break;case $.ui.keyCode.ENTER:a.length&&(this.keydown.blockquote=!1,this.keydown.enterWithinBlockquote=!0);break;case $.ui.keyCode.UP:if(!i||!a.length)return;var f=$(t).closest("div",a[0]),m=f.prev();if("DIV"===m[0].tagName)return;if("BLOCKQUOTE"===m[0].tagName)return;var b=a.prev();0===b.length?this.wutil.setCaretBefore(a):"BLOCKQUOTE"===b[0].tagName?this.caret.sendEnd(b.children("div:last")):(""==$.trim(b.html())&&b.html(this.opts.invisibleSpace),this.caret.setEnd(b)),e.cancel=!0;break;case 83:if($.browser.mobile||$.browser.touch)return;var v=!1;if(navigator.platform.match(/^Mac/)?e.event.ctrlKey&&e.event.altKey&&(v=!0):e.event.altKey&&!e.event.ctrlKey&&(v=!0),v){var w={cancel:!1};WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","submitEditor_"+this.$textarea.wcfIdentify(),w),w.cancel&&(e.cancel=!0)}}},_keyupCallback:function(e){switch(e.event.which){case $.ui.keyCode.BACKSPACE:case $.ui.keyCode.DELETE:this.$editor.find("blockquote").each(function(e,t){var i=$(t);i.children("header").length||i.remove()});break;case $.ui.keyCode.ENTER:for(var t=0,i=this.$editor[0].children.length;i>t;t++){var a=this.$editor[0].children[t];if(a.nodeType===Node.ELEMENT_NODE&&"P"===a.tagName&&!(a.textContent.length>0||a.children.length>1||"BR"===a.children[0].tagName)){for(a=a.children[0];1===a.children.length;)a=a.children[0];if(0===a.children.length&&"BR"===a.tagName){var r=a.parentNode,n=document.createTextNode("");r.appendChild(n),r.removeChild(a)}}}}},observeQuotes:function(){this.$editor.find(".redactorQuoteEdit").off("click.wbbcode").on("click.wbbcode",$.proxy(this.wbbcode._observeQuotesClick,this))},_observeQuotesClick:function(e){var t=$(e.currentTarget).closest("header"),i=$('<span class="redactor-link-tooltip" />');$('<a href="#">'+WCF.Language.get("wcf.bbcode.quote.edit")+"</a>").click($.proxy(function(t){t.preventDefault(),this.wbbcode._openQuoteEditOverlay($(e.currentTarget).closest("blockquote.quoteBox"),!1),$(".redactor-link-tooltip").remove()},this)).appendTo(i);var a=t.offset();i.css({left:a.left+"px",top:a.top+20+"px"}),$(".redactor-link-tooltip").remove(),i.appendTo(document.body),this.selection.remove()},observeCodeListings:function(){this.$editor.find(".codeBox").each(function(e,t){var i=$(t),a=i.find(".redactorEditCodeBox");a.length||(a=$('<div class="redactorEditCodeBox"><div>'+WCF.Language.get("wcf.bbcode.code.edit")+"</div></div>").insertAfter(i.find("> div > div > h3"))),a.off("click.wbbcode").on("click.wbbcode",function(){this.wbbcode._handleInsertCode(i,!1)}.bind(this))}.bind(this))},_openQuoteEditOverlay:function(t,i){this.modal.load("quote",WCF.Language.get("wcf.bbcode.quote."+(i?"insert":"edit")),400);var a=this.modal.createActionButton(this.lang.get("save"));i?(this.selection.save(),a.click($.proxy(function(){var t=$("#redactorQuoteAuthor").val(),i=WCF.String.escapeHTML($("#redactorQuoteLink").val());this.selection.restore(),e=!0;var a=this.selection.getHtml();this.utils.isEmpty(a)&&(a="");var r=this.wbbcode.insertQuoteBBCode(t,i,a);null!==r&&(a.length||($.browser.mozilla&&r.children("br[type=_moz]").replaceWith("<div>"+this.opts.invisibleSpace+"</div>"),this.caret.setStart(r.children("div")[0]))),this.modal.close()},this))):($("#redactorQuoteAuthor").val(t.data("author")),$("#redactorQuoteLink").val(WCF.String.unescapeHTML(t.attr("cite"))),a.click($.proxy(function(){var e=$("#redactorQuoteAuthor").val();
-
-t.data("author",e),t.attr("data-author",e),t.prop("cite",WCF.String.escapeHTML($("#redactorQuoteLink").val())),this.wbbcode._updateQuoteHeader(t),this.modal.close()},this))),this.modal.show()},_updateQuoteHeader:function(e){var t=e.data("author"),i=e.attr("cite");i&&(i=WCF.String.escapeHTML(i)),e.find("> header > h3").empty().append(this.wbbcode._buildQuoteHeader(t,i))},insertQuoteBBCode:function(e,t,i,a){var r="[quote]",n="[/quote]";e&&(r=t?"[quote='"+e+"','"+t+"']":"[quote='"+e+"']");var l=null;if(this.wutil.inWysiwygMode()){var o=WCF.getUUID(),c="";a?c=this.wbbcode.convertToHtml(r+a+n):(c=this.wbbcode.convertToHtml(r+o+n),c=c.replace(o,i.replace(/^<p>/,"").replace(/<\/p>$/,""))),c=c.replace(/^<p>/,"").replace(/<\/p>$/,""),c=c.replace(/<blockquote/,'<blockquote id="'+o+'"'),window.getSelection().rangeCount||(this.wutil.restoreSelection(),window.getSelection().rangeCount||(this.$editor.focus(),window.getSelection().rangeCount||this.wutil.selectionEndOfEditor(),this.wutil.saveSelection())),window.getSelection().getRangeAt(0).deleteContents(),this.wutil.restoreSelection();for(var s=window.getSelection().getRangeAt(0),d=s.startContainer;d;){var h=d.parentNode;if(h===this.$editor[0])break;d=h}if(d&&d.parentNode===this.$editor[0]&&d.innerHTML.length&&(""===d.innerHTML?this.caret.setEnd(d):this.wutil.setCaretAfter(d)),this.insert.html(c,!1),l=this.$editor.find("#"+o),l.length){var p=l.find("> div");if(1==p.length)""===p[0].innerHTML&&(p[0].innerHTML=this.opts.invisibleSpace);else if($.browser.mozilla){var g=l.find("> div > br[type=_moz]");g.length&&($("<div>"+this.opts.invisibleSpace+"</div>").insertBefore(g),g.remove())}l.removeAttr("id"),this.wutil.setCaretAfter(l[0]);var u=l[0].previousElementSibling;null!==u&&"P"===u.nodeName&&""===u.innerHTML&&(u=u.previousElementSibling,null===u||"P"!==u.nodeName||""!==u.innerHTML&&"<br>"!==u.innerHTML||u.parentNode.removeChild(u.nextElementSibling))}this.wbbcode.observeQuotes(),this.wbbcode.fixBlockLevelElements(),this.$toolbar.find("a.re-__wcf_quote").removeClass("redactor-button-disabled")}else this.wutil.insertAtCaret(r+a+n);return this.wutil.saveSelection(),l},_buildQuoteHeader:function(e,t){var i="";return!e&&t&&(e=t,t=""),e?(t&&(i+='<a href="'+t+'" tabindex="-1">'),i+=WCF.Language.get("wcf.bbcode.quote.title.javascript",{quoteAuthor:WCF.String.unescapeHTML(e)}),t&&(i+="</a>")):i="<small>"+WCF.Language.get("wcf.bbcode.quote.title.clickToSet")+"</small>",i},_handleInsertQuote:function(){this.wbbcode._openQuoteEditOverlay(null,!0)},_handleInsertCode:function(e,t){this.modal.load("code",WCF.Language.get("wcf.bbcode.code."+(t?"insert":"edit")),400);var i=this.modal.createActionButton(this.lang.get("save")).addClass("buttonPrimary");if(t){this.selection.get();var a=this.selection.getText();$.browser.mozilla&&(a=a.replace(/\r/g,"").replace(/\u200b/g,""),a=a.replace(/(\n+)/g,function(e,t){var i=t.match(/\n/g).length;for(i=~~(i/2),t="";i>0;)t+="\n",i--;return t})),this.selection.save(),this.modal.show();var r=$("#redactorCodeBox").focus();r.val(a),i.click($.proxy(function(){var e=$("#redactorCodeBox"),t=$("#redactorCodeFilename"),i=$("#redactorCodeHighlighter"),a=$("#redactorCodeLineNumber"),r=e.val().replace(/^\n+/,"").replace(/\n+$/,"");if(0===$.trim(r).length)return void(e.next("small.innerError").length||$('<small class="innerError">'+WCF.Language.get("wcf.global.form.error.empty")+"</small>").insertAfter(e));var n=$.trim(t.val().replace(/['"]/g,"")),l="[code="+i.val()+","+a.val()+(n.length?",'"+n+"'":"")+"]";l.match(/\[code=([^,]+),(\d+)\]/)&&(l="[code="+RegExp.$2+","+RegExp.$1+"]"),l+=r,l+="[/code]",this.wutil.adjustSelectionForBlockElement(),this.wutil.saveSelection();var o=this.wbbcode.convertToHtml(l);this.buffer.set(),this.insert.html(o,!1);var e=this.$editor.find(".codeBox:not(.jsRedactorCodeBox)");this.wbbcode.observeCodeListings(),this.wbbcode.fixBlockLevelElements(),e.attr("contenteditable","false"),this.wutil.setCaretAfter(e[0]),this.modal.close()},this))}else{var n=this.modal.createActionButton(WCF.Language.get("wcf.global.button.delete"));n.click(function(){this.buffer.set(),e.remove(),this.modal.close()}.bind(this)),this.modal.show();var r=$("#redactorCodeBox").focus(),l=$("#redactorCodeFilename"),o=$("#redactorCodeHighlighter"),c=$("#redactorCodeLineNumber");o.val(e.data("highlighter")),l.val(e.data("filename")||"");var s=e.find("> div > ol");c.val(parseInt(s.prop("start")));var d="";s.children("li").each(function(e,t){d+=$(t).text().replace(/^\u200b$/,"")+"\n"}),r.val(d.replace(/^\n+/,"").replace(/\n+$/,"")),i.click($.proxy(function(){var t=r.val().replace(/^\n+/,"").replace(/\n+$/,"");if(0===$.trim(t).length)return void(r.next("small.innerError").length||$('<small class="innerError">'+WCF.Language.get("wcf.global.form.error.empty")+"</small>").insertAfter(r));var i=o.val();e.data("highlighter",i),e.attr("data-highlighter",i);var a=__REDACTOR_CODE_HIGHLIGHTERS[i],n=$.trim(l.val().replace(/['"]/g,""));n?(a+=": "+WCF.String.escapeHTML(n),e.data("filename",n),e.attr("data-filename",n)):(e.removeAttr("data-filename"),e.removeData("filename")),e.data("highlighter",o.val()),e.find("> div > div > h3").html(a);var s=e.find("> div > ol").empty(),d=parseInt(c.val());s.prop("start",d>1?d:1),t=t.split("\n");for(var h="",p=0;p<t.length;p++)h+="<li>"+WCF.String.escapeHTML(t[p])+"</li>";s.append($(h)),this.modal.close()},this))}},fixBlockLevelElements:function(){var e=function(e,t){var i=e[t];i&&i.nodeType===Node.ELEMENT_NODE&&"P"===i.tagName&&(i.innerHTML.length||i.parentElement.removeChild(i))}.bind(this);this.$editor.find("blockquote, .codeBox").each(function(){e(this,"previousElementSibling"),e(this,"nextElementSibling")})},fixFormatting:function(){for(var e=function(t){t.style.removeProperty("text-align");for(var i=0;i<t.children.length;i++)e(t.children[i])},t=0;t<this.alignment.blocks.length;t++){var i=this.alignment.blocks[t];switch(i.tagName){case"BLOCKQUOTE":i.style.removeProperty("text-align"),e(i.children[0]);break;case"DIV":/\bcodeBox\b/.test(i.className)&&e(i)}}}}};
+if(!RedactorPlugins)var RedactorPlugins={};RedactorPlugins.wbbcode=function(){"use strict";var e=!1;return{init:function(){var t=this.$textarea.wcfIdentify();this.opts.initCallback=function(){window.addEventListener("unload",function(){this.code.startSync(),this.$textarea.val(this.wbbcode.convertFromHtml(this.$textarea.val()))}.bind(this)),$.browser.msie&&this.$editor.addClass("msie"),this.$textarea[0].setAttribute("data-is-dirty",!0);var e=$.trim(this.wutil.getOption("woltlab.originalValue"));e.length&&(this.wutil.replaceText(e),this.wutil.selectionEndOfEditor()),delete this.opts.woltlab.originalValue,$(document).trigger("resize"),this.wutil.saveSelection();var t=this.$editor[0],i=this.$textarea[0];setTimeout(function(){$.browser.iOS&&0===t.scrollHeight&&(document.activeElement===t||document.activeElement===i)&&document.activeElement.blur()},10)}.bind(this),this.opts.pasteBeforeCallback=$.proxy(this.wbbcode._pasteBeforeCallback,this),this.opts.pasteCallback=$.proxy(this.wbbcode._pasteCallback,this);var i=this.clean.onSync;this.clean.onSync=function(t){return t=t.replace(/\u200C/g,"__wcf_zwnj__"),t=t.replace(/\u200D/g,"__wcf_zwj__"),e===!0?e=!1:t=t.replace(/<p><br([^>]+)?><\/p>/g,"<p>@@@wcf_empty_line@@@</p>"),t=i.call(this,t),t=t.replace(/__wcf_zwnj__/g,""),t.replace(/__wcf_zwj__/g,"")}.bind(this),this.wutil.getOption("woltlab.autosaveOnce")&&(this.wutil.saveTextToStorage(),delete this.opts.woltlab.autosaveOnce);var a=this.button.get("table");if(a.length){var r=a.data("dropdown");r.find(".redactor-dropdown-add_head").parent().remove(),r.find(".redactor-dropdown-delete_head").parent().remove(),$('<li class="dropdownDivider" />').insertBefore(r.find(".redactor-dropdown-delete_table").parent()),a.click($.proxy(this.wbbcode._tableButtonClick,this))}WCF.System.Event.addListener("com.woltlab.wcf.redactor","insertBBCode_quote_"+t,$.proxy(function(e){e.cancel=!0,this.wbbcode._handleInsertQuote()},this)),WCF.System.Event.addListener("com.woltlab.wcf.redactor","insertBBCode_code_"+t,$.proxy(function(e){e.cancel=!0,this.wbbcode._handleInsertCode(null,!0)},this)),WCF.System.Event.addListener("com.woltlab.wcf.redactor","keydown_"+t,$.proxy(this.wbbcode._keydownCallback,this)),WCF.System.Event.addListener("com.woltlab.wcf.redactor","keyup_"+t,$.proxy(this.wbbcode._keyupCallback,this)),this.code.sync=function(){};var n=$(".redactor-toolbar-tooltip-html:not(.jsWbbcode)").addClass("jsWbbcode").text(WCF.Language.get("wcf.bbcode.button.toggleBBCode")),l=function(e){e.find("br").each(function(e,t){t.children.length&&$(t).empty()})};this.code.toggle=function(){if(this.opts.visual)this.code.startSync(),this.code.showCode(),this.$textarea.val(this.wbbcode.convertFromHtml(this.$textarea.val())),this.button.get("html").children("i").removeClass("fa-square-o").addClass("fa-square"),n.text(WCF.Language.get("wcf.bbcode.button.toggleHTML"));else{if(this.$textarea.val(this.wbbcode.convertToHtml(this.$textarea.val())),this.code.offset=this.$textarea.val().length,this.code.showVisual(),this.wutil.fixDOM(),this.wbbcode.fixBlockLevelElements(),this.wutil.selectionEndOfEditor(),this.wbbcode.observeQuotes(),this.wbbcode.observeCodeListings(),this.button.get("html").children("i").removeClass("fa-square").addClass("fa-square-o"),n.text(WCF.Language.get("wcf.bbcode.button.toggleBBCode")),this.wutil.fixDOM(),l(this.$editor),/ Edge\//.test(navigator.userAgent)){var e=this.$editor[0];window.dtdesign=e,e.childElementCount>1&&""===e.children[0].innerHTML&&e.removeChild(e.children[0])}this.wutil.saveSelection()}}.bind(this),this.wutil.setOption("clickCallback",function(e){e.target===this.$editor[0]&&this.$editor[0].lastElementChild&&"BLOCKQUOTE"===this.$editor[0].lastElementChild.tagName&&this.wutil.setCaretAfter($(this.$editor[0].lastElementChild)),setTimeout(this.wutil.saveSelection.bind(this),10)}.bind(this));var o=this.opts.verifiedTags.indexOf("ul");o>-1&&this.opts.verifiedTags.splice(o,1),WCF.System.Event.addListener("com.woltlab.wcf.redactor","observe_load_"+t,function(){this.wbbcode.observeCodeListings(),this.wbbcode.observeQuotes()}.bind(this)),WCF.System.Event.addListener("com.woltlab.wcf.redactor","fixFormatting_"+t,$.proxy(this.wbbcode.fixFormatting,this))},_tableButtonClick:function(e){var t=$(e.currentTarget);if(t.hasClass("dropact")){var i=this.selection.getBlock()||this.selection.getCurrent(),a=t.data("dropdown");a.children("li").show();var r=a.find("> li > .redactor-dropdown-insert_table").parent();"TD"==i.tagName?r.hide():r.nextAll().hide()}},insertSmiley:function(e,t,i){function a(e){return null===e?!1:(e.nodeType===Node.ELEMENT_NODE&&"SPAN"===e.nodeName||e.nodeType===Node.TEXT_NODE)&&" "===e.textContent?!0:!1}if(i&&this.wbbcode.registerSmiley(e,t),this.opts.visual){this.wutil.restoreSelection();var r=window.getSelection();r.rangeCount||this.focus.setEnd();var n=r.getRangeAt(0);n.deleteContents();var l=document.createElement("img");l.src=t,l.className="smiley",l.alt=e,n.insertNode(l);var o=l,c=l.parentElement;if(!a(l.previousSibling)){var s=document.createTextNode(" ");c.insertBefore(s,l)}if(!a(l.nextSibling)){var s=document.createTextNode(" ");c.lastChild===l?c.appendChild(s):c.insertBefore(s,l.nextSibling),o=s}var n=document.createRange();n.selectNode(o),n.collapse(!1),r.removeAllRanges(),r.addRange(n),this.wutil.saveSelection()}else this.wutil.insertAtCaret(" "+e+" ")},registerSmiley:function(e,t){return __REDACTOR_SMILIES[e]?!1:(__REDACTOR_SMILIES[e]=t,!0)},convertFromHtml:function(e){var t=[];WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","beforeConvertFromHtml",{html:e}),e=e.replace(/(<[^>]+?) data-redactor-tag="[^"]+"/g,"$1"),e=e.replace(/(<[^>]+?) rel="[^"]+"/g,"$1"),e=e.replace(/&#(8203|x200b);/g,""),e=e.replace(/™/gi,"™"),e=e.replace(/©/gi,"©"),e=e.replace(/…/gi,"…"),e=e.replace(/—/gi,"—"),e=e.replace(/‐/gi,"‐");var i={};e=e.replace(/<div([^>]+?)class="codeBox[^"]+"([^>]*?)>\n*<div>[\s\S]+?<ol start="(\d+)">([\s\S]+?)<\/ol>\n*<\/div>\n*<\/div>/g,function(e,t,a,r,n){var l=t+" "+a,o="",c="";l.match(/data-highlighter="([a-zA-Z]+)"/)&&(o=RegExp.$1),l.match(/data-filename="([^"]+)"/)&&(c=$.trim(RegExp.$1));var s=WCF.getUUID();return i[s]={codeContent:n.replace(/<li>/g,"").replace(/<\/li>/g,"\n").replace(/\n$/,""),filename:c.replace(/['"]/g,""),highlighter:"plain"===o?"":o,lineNumber:r>1?r:0},"@@@"+s+"@@@"}),e=e.replace(/\r?\n/g,""),e=e.replace(/<a[^>]*?><\/a>/g,""),e=e.replace(/<p><\/p><table/g,"<table"),e=e.replace(/<\/table><p><\/p>/g,"</table>");for(var a in i)e=e.replace(new RegExp("<p></p>@@@"+a+"@@@<p></p>"),"@@@"+a+"@@@");e=e.replace(/<p><\/p><p>(?!<br>)/g,"<p>@@@wcf_empty_line@@@</p><p>"),e=e.replace(/<br( \/)?><\/p>/g,"</p>");for(var r=e.split(/(<\/?(?:div|p)>)/),n="",l="",o=0;o<r.length;o++){var c=r[o];"<p>"!=c&&"<div>"!=c&&("</p>"==c||"</div>"==c?(l=$.trim(l),"@@@wcf_empty_line@@@"!=l&&(l+="\n"),n+=l,l=""):0==o||o+1==r.length?n+=c:l+=c)}l&&(n+=l,l=""),e=n,e=e.replace(/@@@wcf_empty_line@@@/g,"\n"),e=e.replace(/\n\n$/,"\n"),e=e.replace(/<br>$/,""),e=e.replace(/<br>/g,"\n"),e=e.replace(/<br>/g,""),e=e.replace(/ /gi," "),e=e.replace(/<blockquote([^>]+)>\n?<header[^>]*?>[\s\S]*?<\/header>/gi,function(e,t){var i,a="",r="";return t.match(/data-author="([^"]+)"/)&&(a=WCF.String.unescapeHTML(RegExp.$1)),t.match(/cite="([^"]+)"/)&&(r=WCF.String.unescapeHTML(RegExp.$1)),i=r?"[quote='"+a+"','"+r+"']":a?"[quote='"+a+"']":"[quote]"}),e=e.replace(/(?:\n*)<\/blockquote>\n?/gi,"\n[/quote]\n"),e=e.replace(/<a [^>]*?href=(["'])mailto:(.+?)\1.*?>([\s\S]+?)<\/a>/gi,"[email=$2]$3[/email]"),e=e.replace(/<a[^>]+><\/a>/,""),e=e.replace(/<a [^>]*?href=(["'])(.+?)\1.*?>([\s\S]+?)<\/a>/gi,function(e,t,i,a){return i==a?"[url]"+i+"[/url]":"[url='"+i+"']"+a+"[/url]"}),e=e.replace(/<(?:b|strong)>/gi,function(){return-1===t.indexOf("b")&&t.push("b"),"[b]"}),e=e.replace(/<\/(?:b|strong)>/gi,"[/b]"),e=e.replace(/<(?:i|em)>/gi,function(){return-1===t.indexOf("i")&&t.push("i"),"[i]"}),e=e.replace(/<\/(?:i|em)>/gi,"[/i]"),e=e.replace(/<u>/gi,function(){return-1===t.indexOf("u")&&t.push("u"),"[u]"}),e=e.replace(/<\/u>/gi,"[/u]"),e=e.replace(/<sub>/gi,function(){return-1===t.indexOf("sub")&&t.push("sub"),"[sub]"}),e=e.replace(/<\/sub>/gi,"[/sub]"),e=e.replace(/<sup>/gi,function(){return-1===t.indexOf("sup")&&t.push("sup"),"[sup]"}),e=e.replace(/<\/sup>/gi,"[/sup]"),e=e.replace(/<(?:s(trike)?|del)>/gi,function(){return-1===t.indexOf("s")&&t.push("s"),"[s]"}),e=e.replace(/<\/(?:s(trike)?|del)>/gi,"[/s]");for(var s=e.split(/(<\/?span[^>]*>)/),l=[],d=[],h="",p={11:8,13:10,16:12,19:14,24:18,29:22,32:24,48:36},o=0;o<s.length;o++){var g=s[o];if("</span>"==g){var u=d.pop(),n=u.start+l.pop()+u.end;l.length?l[l.length-1]+=n:h+=n}else if(g.match(/^<span/))if(g.match(/^<span(?:.*?)style="([^"]+)"(?:[^>]*?)>/)){var f,m,b=RegExp.$1;if(b.match(/(?:^|;\s*)color: ?rgb\((\d{1,3}), ?(\d{1,3}), ?(\d{1,3})\);?/i)){var v=RegExp.$1,w=RegExp.$2,C=RegExp.$3,x="0123456789ABCDEF".charAt((v-v%16)/16)+""+"0123456789ABCDEF".charAt(v%16)+("0123456789ABCDEF".charAt((w-w%16)/16)+""+"0123456789ABCDEF".charAt(w%16))+("0123456789ABCDEF".charAt((C-C%16)/16)+""+"0123456789ABCDEF".charAt(C%16));f="[color=#"+x+"]",m="[/color=#"+x+"]",-1===t.indexOf("color")&&t.push("color")}else b.match(/(?:^|;\s*)color: ?([^;]+);?/i)?(f="[color="+RegExp.$1+"]",m="[/color="+RegExp.$1+"]",-1===t.indexOf("color")&&t.push("color")):b.match(/font-size: ?(\d+)(pt|px);?/i)?"pt"==RegExp.$2?(f="[size="+RegExp.$1+"]",m="[/size="+RegExp.$1+"]",-1===t.indexOf("size")&&t.push("size")):p[RegExp.$1]?(f="[size="+p[RegExp.$1]+"]",m="[/size="+p[RegExp.$1]+"]",-1===t.indexOf("size")&&t.push("size")):(f="",m=""):b.match(/font-family: ?([^;]+);?/)?(f="[font='"+RegExp.$1.replace(/'/g,"")+"']",m="[/font='"+RegExp.$1.replace(/'/g,"")+"']",-1===t.indexOf("font")&&t.push("font")):(f='<span style="'+b+'">',m="</span>");l[l.length]="",d[l.length]={start:f,end:m}}else g.match(/^<span class="inlineCode">/)?(l[l.length]="",d[l.length]={start:"[tt]",end:"[/tt]"}):(l[l.length]="",d[l.length]={start:"",end:""});else l.length?l[l.length-1]+=g:h+=g}if(e=h,e=e.replace(/<(div|p) style="text-align: ?(left|center|right|justify);? ?">([\s\S]*?)\n/gi,function(e,i,a,r){return-1===t.indexOf("align")&&t.push("align"),"[align="+a+"]"+$.trim(r)+"[/align="+a+"]\n"}),t.length){for(var E=!0;E;)E=!1,e=e.replace(new RegExp("\\[\\/((?:"+t.join("|")+")=[^\\]]+?)\\]\n\\[\\1\\]","gi"),function(){return E=!0,"\n"});e=e.replace(new RegExp("\\[\\/("+t.join("|")+")=[^\\]]+?\\]","gi"),"[/$1]")}e=e.replace(/ ?<img [^>]*?alt="([^"]+?)"[^>]*?class="smiley"[^>]*?> ?/gi," $1 "),e=e.replace(/ ?<img [^>]*?class="smiley"[^>]*?alt="([^"]+?)"[^>]*?> ?/gi," $1 "),e=e.replace(/<img([^>]*?)class="[^"]*redactorEmbeddedAttachment[^"]*"([^>]*?)>/gi,function(e,t,i){var a,r=t+" "+i;if(!r.match(/data-attachment-id="(\d+)"/))return e;a=RegExp.$1;var n="none",l=null;if(r.match(/style="([^"]+)"/)){for(var o=RegExp.$1.split(";"),c=0;c<o.length;c++){var s=$.trim(o[c]);s.match(/^float: (left|right)$/)?n=RegExp.$1:s.match(/^width: (\d+)px$/)&&(l=RegExp.$1)}if(null!==l)return"[attach="+a+","+n+","+l+"][/attach]";if("none"!==n)return"[attach="+a+","+n+"][/attach]"}return"[attach="+a+"][/attach]"}),e=e.replace(/<img([^>]*)?src=(["'])([^"']+?)\2([^>]*)?>/gi,function(e,t,i,a,r){var n=t+" "+r,l="";n.match(/style="([^"]+)"/)&&(l=RegExp.$1);for(var o="none",c=0,s=l.split(";"),d=0;d<s.length;d++){var h=s[d];h.match(/float: (left|right|none)/)?o=RegExp.$1:h.match(/width: (\d+)px/)&&(c=parseInt(RegExp.$1))}return c?"[img='"+a+"',"+o+","+c+"][/img]":"none"!==o?"[img='"+a+"',"+o+"][/img]":"[img]"+a+"[/img]"}),e=e.replace(/<li>/gi,"[*]"),e=e.replace(/<\/li>/gi,"\n"),e=e.replace(/<ul>/gi,"[list]"),e=e.replace(/<(ol|ul style="list-style-type: decimal")>/gi,"[list=1]"),e=e.replace(/<ul style="list-style-type: (none|circle|square|disc|decimal|lower-roman|upper-roman|decimal-leading-zero|lower-greek|lower-latin|upper-latin|armenian|georgian)">/gi,"[list=$1]"),e=e.replace(/<\/(ul|ol)>/gi,"[/list]"),e=e.replace(/\n?\[list\]/g,"\n[list]"),e=e.replace(/\[\/list\]\n\[\*\]/g,"[/list][*]"),e=e.replace(/\[\/list\]\n\[\/list\]/g,"[/list][/list]"),e=e.replace(/<table[^>]*>/gi,"[table]\n"),e=e.replace(/<\/table>\n?/gi,"[/table]\n"),e=e.replace(/<tbody>([\s\S]*?)<\/tbody>/,function(e,t){return $.trim(t)}),e=e.replace(/<tr><\/tr>/gi,""),e=e.replace(/<tr>/gi,"[tr]\n"),e=e.replace(/<\/tr>/gi,"[/tr]\n"),e=e.replace(/<td style="text-align: ?(left|center|right|justify);? ?">([\s\S]*?)<\/td>/gi,"[td][align=$1]$2[/align][/td]"),e=e.replace(/(\t)*<td>(\t)*/gi,"[td]"),e=e.replace(/(\t)*<\/td>/gi,"[/td]\n");var y={};if(e.replace(/<span id="selection-marker-\d+" class="redactor-selection-marker"><\/span>/,function(e){var t=e.hashCode();return y[t]=e.replace(/\$/g,"$$$$"),"@@"+t+"@@"}),WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","convertFromHtml",{html:e}),e=e.replace(/<[^(<|>)]+>/g,""),$.getLength(y))for(var S in y){var _=new RegExp("@@"+S+"@@","g");e=e.replace(_,y[S])}return $.getLength(i)&&$.each(i,function(t,i){var a=0;i.highlighter&&a++,i.lineNumber&&a++,i.filename&&a++;var r="";switch(a){case 1:r=i.highlighter?i.highlighter:i.filename?"'"+i.filename+"'":i.lineNumber;break;case 2:i.lineNumber&&(r=i.lineNumber),i.highlighter&&(r.length&&(r+=","),r+=i.highlighter),i.filename&&(r.length&&(r+=","),r+="'"+i.filename+"'");break;case 3:r=i.highlighter+","+i.lineNumber+",'"+i.filename+"'"}var n="[code"+(r.length?"="+r:"")+"]"+i.codeContent+"[/code]\n";e=e.replace(new RegExp("@@@"+t+"@@@\n?","g"),n.replace(/\$/g,"$$$"))}),e=e.replace(/</g,"<"),e=e.replace(/>/g,">"),e=e.replace(/&/g,"&"),e=e.replace(/%28/g,"("),e=e.replace(/%29/g,")"),WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","afterConvertFromHtml",{html:e}),e=$.trim(e),e.length&&(e+="\n"),e},convertToHtml:function(e){WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","beforeConvertToHtml",{data:e}),e=this.wutil.removeZeroWidthSpace(e),e=e.replace(/&/g,"&"),e=e.replace(/</g,"<"),e=e.replace(/>/g,">");var t=[],i=new RegExp("\\[("+__REDACTOR_SOURCE_BBCODES.join("|")+")([\\S\\s]+?)\\[\\/\\1\\]","gi");e=e.replace(i,function(e){var i=e.hashCode();return t.push({key:i,value:e.replace(/\$/g,"$$$$")}),"@@"+i+"@@"}),e=e.replace(/\[url\]([^"]+?)\[\/url]/gi,'<a href="$1">$1</a>'+this.opts.invisibleSpace),e=e.replace(/\[url\='([^'"]+)']([\s\S]+?)\[\/url]/gi,'<a href="$1">$2</a>'+this.opts.invisibleSpace),e=e.replace(/\[url\=([^'"\]]+)]([\s\S]+?)\[\/url]/gi,'<a href="$1">$2</a>'+this.opts.invisibleSpace),e=e.replace(/\[email\]([^"]+?)\[\/email]/gi,'<a href="mailto:$1">$1</a>'+this.opts.invisibleSpace),e=e.replace(/\[email\=([^"\]]+)](.+?)\[\/email]/gi,'<a href="mailto:$1">$2</a>'+this.opts.invisibleSpace),e=e.replace(/\[(b|i|s|sub|sup|u)\]\[\1\]/gi,"[$1]"),e=e.replace(/\[(\/(?:b|i|s|sub|sup|u))\]\[\1\]/gi,"[$1]"),e=e.replace(/\[(b|i|s|sub|sup|u)\]\[\/\1\]/gi,""),e=e.replace(/\[b\]([\s\S]*?)\[\/b]/gi,function(e,t){return this.wbbcode._expandFormatting(t,"<strong>","</strong>")}.bind(this)),e=e.replace(/\[i\]([\s\S]*?)\[\/i]/gi,function(e,t){return this.wbbcode._expandFormatting(t,"<em>","</em>")}.bind(this)),e=e.replace(/\[u\]([\s\S]*?)\[\/u]/gi,function(e,t){return this.wbbcode._expandFormatting(t,"<u>","</u>")}.bind(this)),e=e.replace(/\[s\]([\s\S]*?)\[\/s]/gi,function(e,t){return this.wbbcode._expandFormatting(t,"<del>","</del>")}.bind(this)),e=e.replace(/\[sub\]([\s\S]*?)\[\/sub]/gi,function(e,t){return this.wbbcode._expandFormatting(t,"<sub>","</sub>")}.bind(this)),e=e.replace(/\[sup\]([\s\S]*?)\[\/sup]/gi,function(e,t){return this.wbbcode._expandFormatting(t,"<sup>","</sup>")}.bind(this)),e=e.replace(/\[img\]([^"]+?)\[\/img\]/gi,'<img src="$1" />'),e=e.replace(/\[img='?([^"]*?)'?,'?(left|right)'?\]\[\/img\]/gi,function(e,t,i){var a="float: "+i+";";return a+="left"===i?"margin: 0 15px 7px 0":"margin: 0 0 7px 15px",'<img src="'+t+'" style="'+a+'" />'}),e=e.replace(/\[img='?([^"]*?)'?,'?(left|right|none)'?,'?(\d+)'?\]\[\/img\]/gi,function(e,t,i,a){var r="float: "+i+"; width: "+a+"px;";return r+="left"===i?"margin: 0 15px 7px 0":"margin: 0 0 7px 15px",'<img src="'+t+'" style="'+r+'" />'}),e=e.replace(/\[img='?([^"]*?)'?\]\[\/img\]/gi,'<img src="$1" />'),e=e.replace(/\[size=(\d+)\]([\s\S]*?)\[\/size\]/gi,function(e,t,i){return this.wbbcode._expandFormatting(i,'<span style="font-size: '+t+'pt">',"</span>")}.bind(this)),e=e.replace(/\[color=([#a-z0-9]*?)\]([\s\S]*?)\[\/color\]/gi,function(e,t,i){return this.wbbcode._expandFormatting(i,'<span style="color: '+t+'">',"</span>")}.bind(this)),e=e.replace(/\[font='?([a-z,\- ]*?)'?\]([\s\S]*?)\[\/font\]/gi,function(e,t,i){return this.wbbcode._expandFormatting(i,'<span style="font-family: '+t+'">',"</span>")}.bind(this)),e=e.replace(/\[align=(left|right|center|justify)\]([\s\S]*?)\[\/align\]/gi,function(e,t,i){return this.wbbcode._expandFormatting(i,'<p style="text-align: '+t+'">',"</p>")}.bind(this));var a=e.indexOf("[list");if(a>0){var r=e.substr(0,a);r=r.replace(/\[\*\]/g,""),e=r+e.substr(a)}var n=e.lastIndexOf("[/list]");if(-1===n)e=e.replace(/\[\*\]/g,""),e=e.replace(/\[list[^\]]*\]/g,"");else{var r=e.substr(n+7);r=r.replace(/\[\*\]/g,""),e=e.substr(0,n+7)+r}e=e.replace(/\[\*\]([\s\S]*?)(?=\[\*\]|\[\/list\])/gi,function(e,t){return"<li>"+$.trim(t)+"</li>"}),e=e.replace(/\n*(\[list\]<\/li>)/g,"$1"),e=e.replace(/\[list\]/gi,"<ul>"),e=e.replace(/\[list=1\]/gi,'<ul style="list-style-type: decimal">'),e=e.replace(/\[list=a\]/gi,'<ul style="list-style-type: lower-latin">'),e=e.replace(/\[list=(none|circle|square|disc|decimal|lower-roman|upper-roman|decimal-leading-zero|lower-greek|lower-latin|upper-latin|armenian|georgian)\]/gi,'<ul style="list-style-type: $1">'),e=e.replace(/\[\/list\]/gi,"</ul>"),e=e.replace(/\[table\]([\S\s]*?)\[\/table\]/gi,function(e,t){return"[table]"+$.trim(t)+"[/table]"}),e=e.replace(/\[table\]\n*/gi,'<table border="1" cellspacing="1" cellpadding="1" style="width: 500px;">'),e=e.replace(/\[\/table\](\n*)?/gi,function(e,t){return t?(t.match(/\n/g).length>2&&(t=t.replace(/^\n/,"")),"</table>"+t):"</table>"}),e=e.replace(/\[tr\]\n*/gi,"<tr>"),e=e.replace(/\[\/tr\]\n*/gi,"</tr>"),e=e.replace(/\[td\]\n*/gi,"<td>"),e=e.replace(/\[\/td\]\n*/gi,"</td>"),e=e.replace(/<td>([\S\s]*?)<\/td>/gi,function(e,t){var i=$.trim(t);return i.length||(i="​"),"<td>"+i+"</td>"});var l=this.wutil.getOption("woltlab.attachmentUrl"),o=this.wutil.getOption("woltlab.attachmentThumbnailUrl");if(l){var c=this.wbbcode._getImageAttachments();e=e.replace(/\[attach=(\d+)\]\[\/attach\]/g,function(e,t){return t=parseInt(t),void 0!==c[t]?'<img src="'+o.replace(/987654321/,t)+'" class="redactorEmbeddedAttachment redactorDisableResize" data-attachment-id="'+t+'" />':e}),e=e.replace(/\[attach=(\d+),(left|right|none)\]\[\/attach\]/g,function(e,t,i){if(t=parseInt(t),void 0!==c[t]){var a="";return("left"===i||"right"===i)&&(a="float: "+i+";",a+="left"===i?"margin: 0 15px 7px 0":"margin: 0 0 7px 15px"),a=' style="'+a+'"','<img src="'+o.replace(/987654321/,t)+'" class="redactorEmbeddedAttachment redactorDisableResize" data-attachment-id="'+t+'"'+a+" />"}return e}),e=e.replace(/\[attach=(\d+),(left|right|none),(\d+)\]\[\/attach\]/g,function(e,t,i,a){if(t=parseInt(t),void 0!==c[t]){var r="width: "+a+"px; max-height: "+c[t].height+"px; max-width: "+c[t].width+"px;";return("left"===i||"right"===i)&&(r+="float: "+i+";",r+="left"===i?"margin: 0 15px 7px 0":"margin: 0 0 7px 15px"),r=' style="'+r+'"','<img src="'+l.replace(/987654321/,t)+'" class="redactorEmbeddedAttachment" data-attachment-id="'+t+'"'+r+" />"}return e})}for(var s in __REDACTOR_SMILIES){var d=s.replace(/</g,"<").replace(/>/g,">"),h=new RegExp("(\\s|>|^)"+WCF.String.escapeRegExp(d)+"(?=\\s|<|$)","gi");e=e.replace(h,'$1<img src="'+__REDACTOR_SMILIES[s]+'" class="smiley" alt="'+d+'" />')}e=e.replace(/(javascript):/gi,"$1<span></span>:"),e=e.replace(/(\r|\r\n)/g,"\n");for(var p=[],g=[],u=e.split(/(\[(?:\/quote|quote|quote='[^']*?'(?:,'[^']*?')?|quote="[^"]*?"(?:,"[^"]*?")?)\])/i),f=WCF.getUUID();;){for(var m=!1,b=0;b<u.length;b++){var v=u[b];if("[/quote]"===v.toLowerCase()){m=!0;for(var w="",C=u.slice(0,b),x=!1;C.length;){var E=C.pop();if(w=E+w,E.match(/^\[quote/i)){v=w+v;var y=WCF.getUUID();p.push({hashCode:y,content:v.replace(/\$/g,"$$$$")}),g.push(y),v="@@"+y+"@@",x=!0;break}}x||(C=u.slice(0,b),v=f),u=C.concat(v,u.slice(b+1));break}}if(!m)break}e=u.join(""),e=e.replace(new RegExp(f,"g"),"[/quote]"),e=e.replace(/\n*$/,"");var S=[];e=e.replace(/(<li>[\s\S]*?<\/li>)/g,function(e){e=$.trim(e).replace(/\n/g,"<br>");var t=WCF.getUUID();return S.push({key:t,content:e}),t});var r=e.split("\n");e="";for(var b=0,_=r.length;_>b;b++){var k=$.trim(r[b]);if(k.match(/^<([a-z]+)/)||k.match(/<\/([a-z]+)>$/))e+=this.reIsBlock.test(RegExp.$1.toUpperCase())||"TABLE"===RegExp.$1.toUpperCase()?k.match(/^<([a-z]+).*<\/\1>/)?k:k+"<br />":"<p>"+k+"</p>";else{if(k){if(k.match(/^@@([0-9\-]+)@@$/)&&WCF.inArray(RegExp.$1,g)){e+=k;continue}}else k="<br>";e+="<p>"+k+"</p>"}}if(e=e.replace(/<td>([\s\S]+?)<\/td>/g,function(e,t){return t=t.replace(/<br(?: \/)?>(<[uo]l)/g,"$1"),"<td>"+t.replace(/<p><br(?: \/)?><\/p>/g,"<br>").replace(/<p>/g,"").replace(/<\/p>/g,"<br>").replace(/<br>$/,"")+"</td>"}),S.length)for(var b=S.length-1;b>=0;b--)e=e.replace(S[b].key,S[b].content);if(p.length)for(var R=function(e){return e.replace(/^['"]/,"").replace(/['"]$/,"")},T=this,L=function(e){return e.replace(/\[quote(=(['"]).+?\2)?\]([\S\s]*)\[\/quote\]/gi,function(e,t,i,a){var r="",n="";if(t){switch(t=t.substr(1),t=t.split(","),t.length){case 1:r=t[0];break;case 2:r=t[0],n=t[1]}r=WCF.String.escapeHTML(R($.trim(r))),n=WCF.String.escapeHTML(R($.trim(n)))}var l='<blockquote class="quoteBox container containerPadding quoteBoxSimple" cite="'+n+'" data-author="'+r+'"><header contenteditable="false"><h3>'+T.wbbcode._buildQuoteHeader(r,n)+'</h3><a class="redactorQuoteEdit"></a></header>';a=$.trim(a);var o="";if(a.length)for(var c=a.split("\n"),s=0;s<c.length;s++){var d=c[s];if(0===d.length)d=T.opts.invisibleSpace;else if(d.match(/^@@([0-9\-]+)@@$/)&&WCF.inArray(RegExp.$1,g)){o+=d;continue}o+="<div>"+d+"</div>"}else o="<div>"+T.opts.invisibleSpace+"</div>";return l+=o,l+="</blockquote>"})},b=p.length-1;b>=0;b--){var F=p[b],A=new RegExp("@@"+F.hashCode+"@@","g");e=e.replace(A,L(F.content))}if(e=e.replace(/<(?:div|p)><(blockquote|div)/g,"<$1"),e=e.replace(/<\/(blockquote|div)><\/(?:div|p)>/g,"</$1>"),t.length)for(var b=t.length-1;b>=0;b--){var O=t[b],A=new RegExp("@@"+O.key+"@@","g"),B=O.value;B=B.replace(/^\[tt\]([\s\S]+)\[\/tt\]/,function(e,t){var i=t.split("\n");t="";for(var a=0,r=i.length;r>a;a++){var n=i[a];if(n.length)t.length&&(t+="</p><p>"),t+="[tt]"+n+"[/tt]";else{if(0===a||a+1===r)continue;t+=t.match(/\[\/tt\]$/)?"</p><p>"+this.opts.invisibleSpace:"</p><p><br>"}}return t}.bind(this)),B=B.replace(/^\[code([^\]]*)\]([\S\s]*)\[\/code\]$/,function(e,t,i){var a="plain",r=0,n="";if(t){t=t.substring(1),t=t.split(",");var l=function(e){return e.match(/^\d+$/)},o=function(e){return-1!==e.indexOf(".")||e.match(/^(["']).*\1$/)},c=function(e){return void 0!==__REDACTOR_CODE_HIGHLIGHTERS[e]},s=function(e){return e.replace(/^(["'])(.*)\1$/,"$2")};switch(t.length){case 1:l(t[0])?r=parseInt(t[0])>1?t[0]:0:o(t[0])?n=s(t[0]):c(t[0])&&(a=t[0]);break;case 2:l(t[0])?(r=parseInt(t[0])>1?t[0]:0,c(t[1])?a=t[1]:o(t[1])&&(n=s(t[1]))):(c(t[0])&&(a=t[0]),o(t[1])&&(n=s(t[1])));break;case 3:c(t[0])&&(a=t[0]),l(t[1])&&(r=t[1]),o(t[2])&&(n=s(t[2]))}}i=i.replace(/^\n+/,"").replace(/\n+$/,"").split(/\n/);for(var d="",h=0;h<i.length;h++){var p=i[h];p.length||(p=this.opts.invisibleSpace),d+="<li>"+p+"</li>"}return'<div class="codeBox container" contenteditable="false" data-highlighter="'+a+'"'+(n?' data-filename="'+WCF.String.escapeHTML(n)+'"':"")+"><div><div><h3>"+__REDACTOR_CODE_HIGHLIGHTERS[a]+(n?": "+WCF.String.escapeHTML(n):"")+'</h3></div><ol start="'+(r>1?r:1)+'">'+d+"</ol></div></div>"}.bind(this)),e=e.replace(A,B)}return WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","afterConvertToHtml",{data:e}),e},_expandFormatting:function(e,t,i){if(!e.length)return t+this.opts.invisibleSpace+i;var a=e.indexOf("[/td]");if(-1!==a){var r=e.substring(0,a);if(-1===r.indexOf("[td]"))return t+r+i+e.substring(a)}var r=e.split("\n");e="";for(var n=0,l=r.length;l>n;n++){var o=r[n];0===o.length&&(o=this.opts.invisibleSpace),e.length&&(e+="\n"),e+=t+o+i}return e},_pasteBeforeCallback:function(e){var t={1:24,2:22,3:18,4:14,5:12,6:10};return e=e.replace(/<h([1-6])([^>]*)>/g,function(e,i,a){if(a&&a.match(/style="([^"]+?)"/)&&/font-size: ?(\d+|\d+\.\d+)(px|pt|em|rem|%)/.test(RegExp.$1)){var r=$('<div style="width: '+RegExp.$1+RegExp.$2+'; position: absolute;" />').appendTo(document.body),n=parseInt(r[0].clientWidth);r.remove();var l=-1,o=!1;$.each(t,function(e,i){-1===l?l=e:Math.abs(n-i)<Math.abs(n-t[l])&&(l=e),n==i&&(o=!0)}),o||(l=6>l?parseInt(l)+1:l),i=l}return"[size="+t[i]+"]"}),e=e.replace(/<\/h[1-6]>/g,"[/size]"),(/<p class="MsoNormal/.test(e)||/margin-bottom: 0cm/.test(e))&&(console.debug("hit"),e=e.replace(/([^>\s])\n([^<\s])/g,"$1 $2"),e=e.replace(/<a name="[^"]+">/g,"")),e=e.replace(/<o:p> <\/o:p>/g,"<br>"),e=e.replace(/<(article|header)[^>]+>/g,"<div>"),e=e.replace(/<\/(article|header)>/g,"</div>"),e=e.replace(/<(div|p)([^>]+)?><(div|p)([^>]+)?>/g,"<p>"),e=e.replace(/<\/(div|p)><\/(div|p)>/g,"</p>"),e=e.replace(/<(?:div|p|span)[^>]+>/gi,function(e){return e.replace(/ class="[^"]+"/,"")}),e=e.replace(/<\/?wbr[^>]*>/g,""),WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","beforePaste",{html:e}),e},_pasteCallback:function(e){return e=e.replace(/\[size=(\d+)\]/g,'<p><span style="font-size: $1pt">'),e=e.replace(/\[\/size\]/g,"</span></p>"),e=e.replace(/style="([^"]+)"/,function(e,t){for(var i=t.split(";"),a=[],r=0,n=i.length;n>r;r++){var l=i[r];l.match(/^\s*background-color/)||a.push(l)}return'style="'+a.join(";")+'"'}),WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","afterPaste",{html:e}),e},insertAttachment:function(e,t){e=parseInt(e);var i=this.wutil.getOption("woltlab.attachment"+(t?"":"Thumbnail")+"Url"),a=this.wbbcode._getImageAttachments();if(i&&void 0!==a[e]){var r="";t&&(r=' style="width: '+a[e].width+"px; max-height: "+a[e].height+"px; max-width: "+a[e].width+'px;"'),this.wutil.insertDynamic('<img src="'+i.replace(/987654321/,e)+'" class="redactorEmbeddedAttachment'+(t?"":" redactorDisableResize")+'" data-attachment-id="'+e+'"'+r+" />","[attach="+e+(t?",none,"+a[e].width:"")+"][/attach]")}else this.wutil.insertDynamic("[attach="+e+"][/attach]")},removeAttachment:function(e){this.opts.visual&&this.$editor.find("img.redactorEmbeddedAttachment").each(function(t,i){var a=$(i);a.data("attachmentID")==e&&a.remove()})},_getImageAttachments:function(){var e=this.wutil.getOption("woltlab.attachmentImages")||[];if(e.length)return delete this.opts.attachmentImages,e;var t={imageAttachments:{}};return WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","getImageAttachments_"+this.$textarea.wcfIdentify(),t),t.imageAttachments},_keydownCallback:function(e){switch(e.event.which){case $.ui.keyCode.BACKSPACE:case $.ui.keyCode.DELETE:case $.ui.keyCode.DOWN:case $.ui.keyCode.ENTER:case $.ui.keyCode.UP:case 83:break;default:return}this.selection.get();var t=this.selection.getCurrent(),i=this.selection.getParent();i=i?$(i):i;var a=i?i.closest("blockquote.quoteBox",this.$editor.get()[0]):{length:0};switch(e.event.which){case $.ui.keyCode.BACKSPACE:if(this.wutil.isCaret()){var r=!1;if(a.length){for(var n=!0,l=0;l<a[0].children.length;l++){var o=a[0].children[l];if("DIV"===o.tagName&&o.textContent.replace(/\u200b/,"").length){n=!1;break}}if(n)r=!0;else{var c=null===this.selection.implicitRange?this.range:this.selection.implicitRange;if(0===c.startOffset)for(var s,d=c.startContainer;null!==(d=d.parentNode);)if(s=d.previousSibling,null!==s){s.nodeType===Node.ELEMENT_NODE&&"HEADER"===s.nodeName&&(r=!0);break}}}if(r){var h=window.getSelection();h.rangeCount&&h.removeAllRanges();var p=document.createRange();p.selectNode(a[0]||a),h.addRange(p),e.cancel=!0}}break;case $.ui.keyCode.DELETE:if(this.wutil.isCaret()&&this.wutil.isEndOfElement(t)){var g=t.nextElementSibling;if(g&&"BLOCKQUOTE"===g.tagName){var h=window.getSelection();h.rangeCount&&h.removeAllRanges();var p=document.createRange();p.selectNode(g),h.addRange(p),e.cancel=!0}}break;case $.ui.keyCode.DOWN:var u=$(t);if(u.next("blockquote").length)this.caret.setStart(u.next().children("div:first")),e.cancel=!0;else if(i)if(i.next("blockquote").length)this.caret.setStart(i.next().children("div:first")),e.cancel=!0;else if(a.length){var f=u.closest("div",a[0]);f.next().length||(a.next().length?this.caret.setStart(a.next()):this.wutil.setCaretAfter(a),e.cancel=!0)}break;case $.ui.keyCode.ENTER:a.length&&(this.keydown.blockquote=!1,this.keydown.enterWithinBlockquote=!0);break;case $.ui.keyCode.UP:if(!i||!a.length)return;var f=$(t).closest("div",a[0]),m=f.prev();if("DIV"===m[0].tagName)return;if("BLOCKQUOTE"===m[0].tagName)return;var b=a.prev();0===b.length?this.wutil.setCaretBefore(a):"BLOCKQUOTE"===b[0].tagName?this.caret.sendEnd(b.children("div:last")):(""==$.trim(b.html())&&b.html(this.opts.invisibleSpace),this.caret.setEnd(b)),e.cancel=!0;break;case 83:if($.browser.mobile||$.browser.touch)return;var v=!1;if(navigator.platform.match(/^Mac/)?e.event.ctrlKey&&e.event.altKey&&(v=!0):e.event.altKey&&!e.event.ctrlKey&&(v=!0),v){var w={cancel:!1};WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","submitEditor_"+this.$textarea.wcfIdentify(),w),w.cancel&&(e.cancel=!0)}}},_keyupCallback:function(e){switch(e.event.which){case $.ui.keyCode.BACKSPACE:case $.ui.keyCode.DELETE:this.$editor.find("blockquote").each(function(e,t){var i=$(t);i.children("header").length||i.remove()});break;case $.ui.keyCode.ENTER:for(var t=0,i=this.$editor[0].children.length;i>t;t++){var a=this.$editor[0].children[t];if(a.nodeType===Node.ELEMENT_NODE&&"P"===a.tagName&&!(a.textContent.length>0||a.children.length>1||"BR"===a.children[0].tagName)){for(a=a.children[0];1===a.children.length;)a=a.children[0];if(0===a.children.length&&"BR"===a.tagName){var r=a.parentNode,n=document.createTextNode("");r.appendChild(n),r.removeChild(a)}}}}},observeQuotes:function(){this.$editor.find(".redactorQuoteEdit").off("click.wbbcode").on("click.wbbcode",$.proxy(this.wbbcode._observeQuotesClick,this))},_observeQuotesClick:function(e){var t=$(e.currentTarget).closest("header"),i=$('<span class="redactor-link-tooltip" />');$('<a href="#">'+WCF.Language.get("wcf.bbcode.quote.edit")+"</a>").click($.proxy(function(t){t.preventDefault(),this.wbbcode._openQuoteEditOverlay($(e.currentTarget).closest("blockquote.quoteBox"),!1),$(".redactor-link-tooltip").remove()},this)).appendTo(i),$('<a href="#">'+WCF.Language.get("wcf.bbcode.quote.delete")+"</a>").click(function(e){e.preventDefault();var i=t.parent(),a=i.parent();i.remove(),$(".redactor-link-tooltip").remove(),"BLOCKQUOTE"===a[0].nodeName&&0===a.children("div").length&&$("<div></div>").appendTo(a)}).appendTo(i);var a=t.offset();i.css({left:a.left+"px",top:a.top+20+"px"}),$(".redactor-link-tooltip").remove(),i.appendTo(document.body),this.selection.remove()},observeCodeListings:function(){this.$editor.find(".codeBox").each(function(e,t){var i=$(t),a=i.find(".redactorEditCodeBox");a.length||(a=$('<div class="redactorEditCodeBox"><div>'+WCF.Language.get("wcf.bbcode.code.edit")+"</div></div>").insertAfter(i.find("> div > div > h3"))),a.off("click.wbbcode").on("click.wbbcode",function(){this.wbbcode._handleInsertCode(i,!1)}.bind(this))}.bind(this))},_openQuoteEditOverlay:function(t,i){this.modal.load("quote",WCF.Language.get("wcf.bbcode.quote."+(i?"insert":"edit")),400);var a=this.modal.createActionButton(this.lang.get("save"));i?(this.selection.save(),a.click($.proxy(function(){var t=$("#redactorQuoteAuthor").val(),i=WCF.String.escapeHTML($("#redactorQuoteLink").val());this.selection.restore(),e=!0;var a=this.selection.getHtml();this.utils.isEmpty(a)&&(a="");var r=this.wbbcode.insertQuoteBBCode(t,i,a);null!==r&&(a.length||($.browser.mozilla&&r.children("br[type=_moz]").replaceWith("<div>"+this.opts.invisibleSpace+"</div>"),
+this.caret.setStart(r.children("div")[0]))),this.modal.close()},this))):($("#redactorQuoteAuthor").val(t.data("author")),$("#redactorQuoteLink").val(WCF.String.unescapeHTML(t.attr("cite"))),a.click($.proxy(function(){var e=$("#redactorQuoteAuthor").val();t.data("author",e),t.attr("data-author",e),t.prop("cite",WCF.String.escapeHTML($("#redactorQuoteLink").val())),this.wbbcode._updateQuoteHeader(t),this.modal.close()},this))),this.modal.show()},_updateQuoteHeader:function(e){var t=e.data("author"),i=e.attr("cite");i&&(i=WCF.String.escapeHTML(i)),e.find("> header > h3").empty().append(this.wbbcode._buildQuoteHeader(t,i))},insertQuoteBBCode:function(e,t,i,a){var r="[quote]",n="[/quote]";e&&(r=t?"[quote='"+e+"','"+t+"']":"[quote='"+e+"']");var l=null;if(this.wutil.inWysiwygMode()){var o=WCF.getUUID(),c="";a?c=this.wbbcode.convertToHtml(r+a+n):(c=this.wbbcode.convertToHtml(r+o+n),c=c.replace(o,i.replace(/^<p>/,"").replace(/<\/p>$/,""))),c=c.replace(/^<p>/,"").replace(/<\/p>$/,""),c=c.replace(/<blockquote/,'<blockquote id="'+o+'"'),window.getSelection().rangeCount||(this.wutil.restoreSelection(),window.getSelection().rangeCount||(this.$editor.focus(),window.getSelection().rangeCount||this.wutil.selectionEndOfEditor(),this.wutil.saveSelection())),window.getSelection().getRangeAt(0).deleteContents(),this.wutil.restoreSelection();for(var s=window.getSelection().getRangeAt(0),d=s.startContainer;d;){var h=d.parentNode;if(h===this.$editor[0])break;d=h}if(d&&d.parentNode===this.$editor[0]&&d.innerHTML.length&&(""===d.innerHTML?this.caret.setEnd(d):this.wutil.setCaretAfter(d)),this.insert.html(c,!1),l=this.$editor.find("#"+o),l.length){var p=l.find("> div");if(1==p.length)""===p[0].innerHTML&&(p[0].innerHTML=this.opts.invisibleSpace);else if($.browser.mozilla){var g=l.find("> div > br[type=_moz]");g.length&&($("<div>"+this.opts.invisibleSpace+"</div>").insertBefore(g),g.remove())}l.removeAttr("id"),this.wutil.setCaretAfter(l[0]);var u=l[0].previousElementSibling;null!==u&&"P"===u.nodeName&&""===u.innerHTML&&(u=u.previousElementSibling,null===u||"P"!==u.nodeName||""!==u.innerHTML&&"<br>"!==u.innerHTML||u.parentNode.removeChild(u.nextElementSibling))}this.wbbcode.observeQuotes(),this.wbbcode.fixBlockLevelElements(),this.$toolbar.find("a.re-__wcf_quote").removeClass("redactor-button-disabled")}else this.wutil.insertAtCaret(r+a+n);return this.wutil.saveSelection(),l},_buildQuoteHeader:function(e,t){var i="";return!e&&t&&(e=t,t=""),e?(t&&(i+='<a href="'+t+'" tabindex="-1">'),i+=WCF.Language.get("wcf.bbcode.quote.title.javascript",{quoteAuthor:WCF.String.unescapeHTML(e)}),t&&(i+="</a>")):i="<small>"+WCF.Language.get("wcf.bbcode.quote.title.clickToSet")+"</small>",i},_handleInsertQuote:function(){this.wbbcode._openQuoteEditOverlay(null,!0)},_handleInsertCode:function(e,t){this.modal.load("code",WCF.Language.get("wcf.bbcode.code."+(t?"insert":"edit")),400);var i=this.modal.createActionButton(this.lang.get("save")).addClass("buttonPrimary");if(t){this.selection.get();var a=this.selection.getText();$.browser.mozilla&&(a=a.replace(/\r/g,"").replace(/\u200b/g,""),a=a.replace(/(\n+)/g,function(e,t){var i=t.match(/\n/g).length;for(i=~~(i/2),t="";i>0;)t+="\n",i--;return t})),this.selection.save(),this.modal.show();var r=$("#redactorCodeBox").focus();r.val(a),i.click($.proxy(function(){var e=$("#redactorCodeBox"),t=$("#redactorCodeFilename"),i=$("#redactorCodeHighlighter"),a=$("#redactorCodeLineNumber"),r=e.val().replace(/^\n+/,"").replace(/\n+$/,"");if(0===$.trim(r).length)return void(e.next("small.innerError").length||$('<small class="innerError">'+WCF.Language.get("wcf.global.form.error.empty")+"</small>").insertAfter(e));var n=$.trim(t.val().replace(/['"]/g,"")),l="[code="+i.val()+","+a.val()+(n.length?",'"+n+"'":"")+"]";l.match(/\[code=([^,]+),(\d+)\]/)&&(l="[code="+RegExp.$2+","+RegExp.$1+"]"),l+=r,l+="[/code]",this.wutil.adjustSelectionForBlockElement(),this.wutil.saveSelection();var o=this.wbbcode.convertToHtml(l);this.buffer.set(),this.insert.html(o,!1);var e=this.$editor.find(".codeBox:not(.jsRedactorCodeBox)");this.wbbcode.observeCodeListings(),this.wbbcode.fixBlockLevelElements(),e.attr("contenteditable","false"),this.wutil.setCaretAfter(e[0]),this.modal.close()},this))}else{var n=this.modal.createActionButton(WCF.Language.get("wcf.global.button.delete"));n.click(function(){this.buffer.set(),e.remove(),this.modal.close()}.bind(this)),this.modal.show();var r=$("#redactorCodeBox").focus(),l=$("#redactorCodeFilename"),o=$("#redactorCodeHighlighter"),c=$("#redactorCodeLineNumber");o.val(e.data("highlighter")),l.val(e.data("filename")||"");var s=e.find("> div > ol");c.val(parseInt(s.prop("start")));var d="";s.children("li").each(function(e,t){d+=$(t).text().replace(/^\u200b$/,"")+"\n"}),r.val(d.replace(/^\n+/,"").replace(/\n+$/,"")),i.click($.proxy(function(){var t=r.val().replace(/^\n+/,"").replace(/\n+$/,"");if(0===$.trim(t).length)return void(r.next("small.innerError").length||$('<small class="innerError">'+WCF.Language.get("wcf.global.form.error.empty")+"</small>").insertAfter(r));var i=o.val();e.data("highlighter",i),e.attr("data-highlighter",i);var a=__REDACTOR_CODE_HIGHLIGHTERS[i],n=$.trim(l.val().replace(/['"]/g,""));n?(a+=": "+WCF.String.escapeHTML(n),e.data("filename",n),e.attr("data-filename",n)):(e.removeAttr("data-filename"),e.removeData("filename")),e.data("highlighter",o.val()),e.find("> div > div > h3").html(a);var s=e.find("> div > ol").empty(),d=parseInt(c.val());s.prop("start",d>1?d:1),t=t.split("\n");for(var h="",p=0;p<t.length;p++)h+="<li>"+WCF.String.escapeHTML(t[p])+"</li>";s.append($(h)),this.modal.close()},this))}},fixBlockLevelElements:function(){var e=function(e,t){var i=e[t];i&&i.nodeType===Node.ELEMENT_NODE&&"P"===i.tagName&&(i.innerHTML.length||i.parentElement.removeChild(i))}.bind(this);this.$editor.find("blockquote, .codeBox").each(function(){e(this,"previousElementSibling"),e(this,"nextElementSibling")})},fixFormatting:function(){for(var e=function(t){t.style.removeProperty("text-align");for(var i=0;i<t.children.length;i++)e(t.children[i])},t=0;t<this.alignment.blocks.length;t++){var i=this.alignment.blocks[t];switch(i.tagName){case"BLOCKQUOTE":i.style.removeProperty("text-align"),e(i.children[0]);break;case"DIV":/\bcodeBox\b/.test(i.className)&&e(i)}}}}};
// wbutton.js
if(!RedactorPlugins)var RedactorPlugins={};RedactorPlugins.wbutton=function(){"use strict";return{_bbcodes:{},init:function(){this._bbcodes={};for(var t=0,e=__REDACTOR_BUTTONS.length;e>t;t++)this.wbutton._addBBCodeButton(__REDACTOR_BUTTONS[t]);for(var n={html:"fa-square-o",bold:"fa-bold",italic:"fa-italic",underline:"fa-underline",deleted:"fa-strikethrough",subscript:"fa-subscript",superscript:"fa-superscript",orderedlist:"fa-list-ol",unorderedlist:"fa-list-ul",outdent:"fa-outdent",indent:"fa-indent",link:"fa-link",alignment:"fa-align-left",table:"fa-table"},i={fontcolor:WCF.Language.get("wcf.bbcode.button.fontColor"),fontfamily:WCF.Language.get("wcf.bbcode.button.fontFamily"),fontsize:WCF.Language.get("wcf.bbcode.button.fontSize"),image:WCF.Language.get("wcf.bbcode.button.image"),subscript:WCF.Language.get("wcf.bbcode.button.subscript"),superscript:WCF.Language.get("wcf.bbcode.button.superscript")},a=this.wutil.getOption("buttons"),o="",t=0,e=a.length;e>t;t++){var s=a[t];if("separator"!=s){var r=this.button.get(s);r.length?(n[s]&&this.button.setAwesome(s,n[s]),"table"===s&&o&&r.parent().insertAfter(this.button.get(o).parent())):this.wbutton._addCoreButton(s,i[s]?i[s]:null,n[s]?n[s]:null,o),o=s}else this.button.get(o).parent().addClass("separator")}if(this.button.addCallback(this.button.get("image"),$.proxy(this.wbutton.insertImage,this)),this.utils.isDesktop()){var l=this.button.addAfter("html","undo",WCF.Language.get("wcf.bbcode.button.undo")),u=this.button.addAfter("undo","redo",WCF.Language.get("wcf.bbcode.button.redo"));this.button.addCallback(l,this.buffer.undo),this.button.addCallback(u,this.buffer.redo),u.parent().addClass("separator")}},_addCoreButton:function(t,e,n,i){var a={title:null===e?t:e};("subscript"===t||"superscript"===t)&&(a.command=t);var o=this.button.build(t,a);$("<li />").append(o).insertAfter(this.button.get(i).parent()),null!==n&&this.button.setAwesome(t,n)},_addBBCodeButton:function(t){var e="__wcf_"+t.name,n=this.button.add(e,t.label);this.button.addCallback(n,this.wbutton._insertBBCode),this._bbcodes[e]={name:t.name,voidElement:t.voidElement===!0},t.icon.match(/^fa\-[a-z\-]+$/)?this.button.setAwesome(e,t.icon):n.css("background-image","url("+__REDACTOR_ICON_PATH+t.icon+")")},_insertBBCode:function(t){var e=this._bbcodes[t].name,n={buttonName:t,cancel:!1,redactor:this};if(WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","insertBBCode_"+e+"_"+this.$textarea.wcfIdentify(),n),n.cancel===!1){var i=this.selection.getHtml();i=i.replace(/<p>@@@wcf_empty_line@@@<\/p>/g,"<p><br></p>");if(this.buffer.set(),this.utils.browser("mozilla")&&!i.length){var a=getSelection().getRangeAt(0).startContainer;a.nodeType===Node.ELEMENT_NODE&&"P"===a.tagName&&"<br>"===a.innerHTML&&a.removeChild(a.children[0])}this._bbcodes[t].voidElement?this.insert.html(i+this.selection.getMarkerAsHtml()+"["+e+"]",!1):this.insert.html("["+e+"]"+i+this.selection.getMarkerAsHtml()+"[/"+e+"]",!1),this.selection.restore()}},insertImage:function(){this.image.show()},_insertImage:function(){var t=$("#redactor-image-link-source"),e=t.val().trim();if(e.length){this.buffer.set();var n=$("#redactor-image-align").val(),i="";("left"===n||"right"===n)&&(i=' style="float: '+n+'"'),this.insert.html('<img src="'+e+'"'+i+">",!1),this.modal.close(),this.observe.images()}else t.next("small.innerError")||$('<small class="innerError">'+WCF.Language.get("wcf.global.form.error.empty")+"</small>").insertAfter(t)}}};
// wfontcolor.js