// wbbcode.js
if(!RedactorPlugins){var RedactorPlugins={}}RedactorPlugins.wbbcode=function(){return{init:function(){var d=this.$textarea.wcfIdentify();this.opts.initCallback=(function(){if($.browser.msie){this.$editor.addClass("msie")}var h=$.trim(this.wutil.getOption("woltlab.originalValue"));if(h.length){this.wutil.replaceText(h);this.wutil.selectionEndOfEditor()}delete this.opts.woltlab.originalValue;$(document).trigger("resize");this.wutil.saveSelection()}).bind(this);this.opts.pasteBeforeCallback=$.proxy(this.wbbcode._pasteBeforeCallback,this);this.opts.pasteCallback=$.proxy(this.wbbcode._pasteCallback,this);var c=this.clean.onSync;this.clean.onSync=function(h){h=h.replace(/<p><br([^>]+)?><\/p>/g,"<p>@@@wcf_empty_line@@@</p>");return c.call(self,h)};if(this.wutil.getOption("woltlab.autosaveOnce")){this.wutil.saveTextToStorage();delete this.opts.woltlab.autosaveOnce}var b=this.button.get("table");if(b.length){var g=b.data("dropdown");g.find(".redactor-dropdown-add_head").parent().remove();g.find(".redactor-dropdown-delete_head").parent().remove();$('<li class="dropdownDivider" />').insertBefore(g.find(".redactor-dropdown-delete_table").parent());b.click($.proxy(this.wbbcode._tableButtonClick,this))}WCF.System.Event.addListener("com.woltlab.wcf.redactor","insertBBCode_quote_"+d,$.proxy(function(h){h.cancel=true;this.wbbcode._handleInsertQuote()},this));WCF.System.Event.addListener("com.woltlab.wcf.redactor","insertBBCode_code_"+d,$.proxy(function(h){h.cancel=true;this.wbbcode._handleInsertCode(null,true)},this));WCF.System.Event.addListener("com.woltlab.wcf.redactor","keydown_"+d,$.proxy(this.wbbcode._keydownCallback,this));WCF.System.Event.addListener("com.woltlab.wcf.redactor","keyup_"+d,$.proxy(this.wbbcode._keyupCallback,this));this.code.sync=function(){};var e=$(".redactor-toolbar-tooltip-html:not(.jsWbbcode)").addClass("jsWbbcode").text(WCF.Language.get("wcf.bbcode.button.toggleBBCode"));var f=function(h){h.find("br").each(function(i,j){if(j.children.length){$(j).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");e.text(WCF.Language.get("wcf.bbcode.button.toggleHTML"))}else{this.$textarea.val(this.wbbcode.convertToHtml(this.$textarea.val()));this.code.offset=this.$textarea.val().length;this.code.showVisual();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");e.text(WCF.Language.get("wcf.bbcode.button.toggleBBCode"));this.wutil.fixDOM();f(this.$editor);this.wutil.saveSelection()}}).bind(this);this.wutil.setOption("clickCallback",(function(h){this.wutil.saveSelection();if(h.target===this.$editor[0]){if(this.$editor[0].lastElementChild&&this.$editor[0].lastElementChild.tagName==="BLOCKQUOTE"){this.wutil.setCaretAfter($(this.$editor[0].lastElementChild))}}}).bind(this));var a=this.opts.verifiedTags.indexOf("ul");if(a>-1){this.opts.verifiedTags.splice(a,1)}},_tableButtonClick:function(b){var c=$(b.currentTarget);if(!c.hasClass("dropact")){return}var a=this.selection.getBlock()||this.selection.getCurrent();var d=c.data("dropdown");d.children("li").show();var e=d.find("> li > .redactor-dropdown-insert_table").parent();if(a.tagName=="TD"){e.hide()}else{e.nextAll().hide()}},insertSmiley:function(a,b,c){if(c){this.wbbcode.registerSmiley(a,b)}if(this.opts.visual){this.insert.html(' <img src="'+b+'" class="smiley" alt="'+a+'" /> ',false)}else{this.wutil.insertAtCaret(" "+a+" ")}},registerSmiley:function(a,b){if(__REDACTOR_SMILIES[a]){return false}__REDACTOR_SMILIES[a]=b;return true},convertFromHtml:function(l){WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","beforeConvertFromHtml",{html:l});l=l.replace(/(<[^>]+?) data-redactor-tag="[^"]+"/g,"$1");l=l.replace(/&#(8203|x200b);/g,"");l=l.replace(/™/gi,"\u2122");l=l.replace(/©/gi,"\u00a9");l=l.replace(/…/gi,"\u2026");l=l.replace(/—/gi,"\u2014");l=l.replace(/‐/gi,"\u2010");var q={};l=l.replace(/<div class="codeBox[^"]+"(.*?)>\n*<div>[\s\S]+?<ol start="(\d+)">([\s\S]+?)<\/ol>\n*<\/div>\n*<\/div>/g,function(A,B,y,D){var C="";var x="";if(B.match(/data-highlighter="([a-zA-Z]+)"/)){C=RegExp.$1}if(B.match(/data-filename="([^"]+)"/)){x=$.trim(RegExp.$1)}var z=WCF.getUUID();q[z]={codeContent:D.replace(/<li>/g,"").replace(/<\/li>/g,"\n"),filename:x.replace(/['"]/g,""),highlighter:(C==="plain"?"":C),lineNumber:(y>1?y:0)};return"@@@"+z+"@@@"});l=l.replace(/\r?\n/g,"");l=l.replace(/<a[^>]*?><\/a>/g,"");l=l.replace(/<p><\/p>/g,"");l=l.replace(/<br( \/)?><\/p>/g,"</p>");var g=l.split(/(<\/?(?:div|p)>)/);var h="";var v="";for(var a=0;a<g.length;a++){var w=g[a];if(w=="<p>"||w=="<div>"){continue}else{if(w=="</p>"||w=="</div>"){v=$.trim(v);if(v!="@@@wcf_empty_line@@@"){v+="\n"}h+=v;v=""}else{if(a==0||a+1==g.length){h+=w}else{v+=w}}}}if(v){h+=v;v=""}l=h;l=l.replace(/@@@wcf_empty_line@@@/g,"\n");l=l.replace(/\n\n$/,"\n");l=l.replace(/<br>$/,"");l=l.replace(/<br>/g,"\n");l=l.replace(/<br>/g,"");l=l.replace(/ /gi," ");l=l.replace(/<blockquote([^>]+)>\n?<header[^>]*?>[\s\S]*?<\/header>/gi,function(z,y,B){var C;var A="";var x="";if(y.match(/data-author="([^"]+)"/)){A=WCF.String.unescapeHTML(RegExp.$1)}if(y.match(/cite="([^"]+)"/)){x=WCF.String.unescapeHTML(RegExp.$1)}if(x){C="[quote='"+A+"','"+x+"']"}else{if(A){C="[quote='"+A+"']"}else{C="[quote]"}}return C});l=l.replace(/(?:\n*)<\/blockquote>\n?/gi,"[/quote]\n");l=l.replace(/<a [^>]*?href=(["'])mailto:(.+?)\1.*?>([\s\S]+?)<\/a>/gi,"[email=$2]$3[/email]");l=l.replace(/<a[^>]+><\/a>/,"");l=l.replace(/<a [^>]*?href=(["'])(.+?)\1.*?>([\s\S]+?)<\/a>/gi,function(A,y,z,B){if(z==B){return"[url]"+z+"[/url]"}return"[url='"+z+"']"+B+"[/url]"});l=l.replace(/<(?:b|strong)>/gi,"[b]");l=l.replace(/<\/(?:b|strong)>/gi,"[/b]");l=l.replace(/<(?:i|em)>/gi,"[i]");l=l.replace(/<\/(?:i|em)>/gi,"[/i]");l=l.replace(/<u>/gi,"[u]");l=l.replace(/<\/u>/gi,"[/u]");l=l.replace(/<sub>/gi,"[sub]");l=l.replace(/<\/sub>/gi,"[/sub]");l=l.replace(/<sup>/gi,"[sup]");l=l.replace(/<\/sup>/gi,"[/sup]");l=l.replace(/<(?:s(trike)?|del)>/gi,"[s]");l=l.replace(/<\/(?:s(trike)?|del)>/gi,"[/s]");var e=l.split(/(<\/?span[^>]*>)/);var v=[];var n=[];var o="";var c={11:8,13:10,16:12,19:14,24:18,29:22,32:24,48:36};for(var a=0;a<e.length;a++){var i=e[a];if(i=="</span>"){var d=n.pop();var h=d.start+$.trim(v.pop())+d.end;if(v.length){v[v.length-1]+=h}else{o+=h}}else{if(i.match(/^<span/)){if(i.match(/^<span(?:.*?)style="([^"]+)"(?:[^>]*?)>/)){var k=RegExp.$1;var t;var m;if(k.match(/color: ?rgb\((\d{1,3}), ?(\d{1,3}), ?(\d{1,3})\);?/i)){var s=RegExp.$1;var b=RegExp.$2;var f=RegExp.$3;var p=("0123456789ABCDEF".charAt((s-s%16)/16)+""+"0123456789ABCDEF".charAt(s%16))+""+("0123456789ABCDEF".charAt((b-b%16)/16)+""+"0123456789ABCDEF".charAt(b%16))+""+("0123456789ABCDEF".charAt((f-f%16)/16)+""+"0123456789ABCDEF".charAt(f%16));t="[color=#"+p+"]";m="[/color]"}else{if(k.match(/color: ?([^;]+);?/i)){t="[color="+RegExp.$1+"]";m="[/color]"}else{if(k.match(/font-size: ?(\d+)(pt|px);?/i)){if(RegExp.$2=="pt"){t="[size="+RegExp.$1+"]";m="[/size]"}else{if(c[RegExp.$1]){t="[size="+c[RegExp.$1]+"]";m="[/size]"}else{t="";m=""}}}else{if(k.match(/font-family: ?([^;]+);?/)){t="[font='"+RegExp.$1.replace(/'/g,"")+"']";m="[/font]"}else{t='<span style="'+k+'">';m="</span>"}}}}v[v.length]="";n[v.length]={start:t,end:m}}else{if(i.match(/^<span class="inlineCode">/)){v[v.length]="";n[v.length]={start:"[tt]",end:"[/tt]"}}else{v[v.length]="";n[v.length]={start:"",end:""}}}}else{if(v.length){v[v.length-1]+=i}else{o+=i}}}}l=o;l=l.replace(/<(div|p) style="text-align: ?(left|center|right|justify);? ?">([\s\S]*?)\n/gi,function(y,x,A,z){return"[align="+A+"]"+$.trim(z)+"[/align]"});l=l.replace(/ ?<img [^>]*?alt="([^"]+?)" class="smiley".*?> ?/gi," $1 ");l=l.replace(/ ?<img [^>]*?class="smiley" alt="([^"]+?)".*?> ?/gi," $1 ");l=l.replace(/<img [^>]*?class="redactorEmbeddedAttachment[^"]*" data-attachment-id="(\d+)"( style="([^"]+)")?>/gi,function(A,D,x,B){var C="none";var z=null;if(B){B=B.split(";");for(var E=0;E<B.length;E++){var y=$.trim(B[E]);if(y.match(/^float: (left|right)$/)){C=RegExp.$1}else{if(y.match(/^width: (\d+)px$/)){z=RegExp.$1}}}if(z!==null){return"[attach="+D+","+C+","+z+"][/attach]"}else{if(C!=="none"){return"[attach="+D+","+C+"][/attach]"}}}return"[attach="+D+"][/attach]"});l=l.replace(/<img [^>]*?src=(["'])([^"']+?)\1 style="([^"]+)".*?>/gi,function(C,F,y,z){var B="none";var A=0;var D=z.split(";");for(var E=0;E<D.length;E++){var x=D[E];if(x.match(/float: (left|right|none)/)){B=RegExp.$1}else{if(x.match(/width: (\d+)px/)){A=parseInt(RegExp.$1)}}}if(A){return"[img='"+y+"',"+B+","+A+"][/img]"}else{if(B!=="none"){return"[img='"+y+"',"+B+"][/img]"}}return"[img]"+y+"[/img]"});l=l.replace(/<img [^>]*?src=(["'])([^"']+?)\1.*?>/gi,"[img]$2[/img]");l=l.replace(/<li>/gi,"[*]");l=l.replace(/<\/li>/gi,"");l=l.replace(/<ul>/gi,"[list]");l=l.replace(/<(ol|ul style="list-style-type: decimal")>/gi,"[list=1]");l=l.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]");l=l.replace(/<\/(ul|ol)>/gi,"[/list]");l=l.replace(/<table[^>]*>/gi,"[table]\n");l=l.replace(/<\/table>/gi,"[/table]\n");l=l.replace(/<tbody>([\s\S]*?)<\/tbody>/,function(x,y){return $.trim(y)});l=l.replace(/<tr><\/tr>/gi,"");l=l.replace(/<tr>/gi,"[tr]\n");l=l.replace(/<\/tr>/gi,"[/tr]\n");l=l.replace(/<td style="text-align: ?(left|center|right|justify);? ?">([\s\S]*?)<\/td>/gi,"[td][align=$1]$2[/align][/td]");l=l.replace(/(\t)*<td>(\t)*/gi,"[td]");l=l.replace(/(\t)*<\/td>/gi,"[/td]\n");var u={};l.replace(/<span id="selection-marker-\d+" class="redactor-selection-marker"><\/span>/,function(x){var y=x.hashCode();u[y]=x.replace(/\$/g,"$$$$");return"@@"+y+"@@"});WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","convertFromHtml",{html:l});l=l.replace(/<[^(<|>)]+>/g,"");if($.getLength(u)){for(var j in u){var r=new RegExp("@@"+j+"@@","g");data=data.replace(r,u[j])}}if($.getLength(q)){$.each(q,function(z,B){var y=0;if(B.highlighter){y++}if(B.lineNumber){y++}if(B.filename){y++}var x="";switch(y){case 1:if(B.highlighter){x=B.highlighter}else{if(B.filename){x="'"+B.filename+"'"}else{x=B.lineNumber}}break;case 2:if(B.highlighter){x=B.highlighter}if(B.lineNumber){if(x.length){x+=","}x+=B.lineNumber}if(B.filename){if(x.length){x+=","}x+="'"+B.filename+"'"}break;case 3:x=B.highlighter+","+B.lineNumber+",'"+B.filename+"'";break}var A="[code"+(x.length?"="+x:"")+"]"+B.codeContent+"[/code]\n";l=l.replace(new RegExp("@@@"+z+"@@@","g"),A)})}l=l.replace(/</g,"<");l=l.replace(/>/g,">");l=l.replace(/&/g,"&");l=l.replace(/%28/g,"(");l=l.replace(/%29/g,")");WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","afterConvertFromHtml",{html:l});l=$.trim(l);if(l.length){l+="\n"}return l},convertToHtml:function(F){WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","beforeConvertToHtml",{data:F});F=this.wutil.removeZeroWidthSpace(F);F=F.replace(/&/g,"&");F=F.replace(/</g,"<");F=F.replace(/>/g,">");var s=[];var n=new RegExp("\\[("+__REDACTOR_SOURCE_BBCODES.join("|")+")([\\S\\s]+?)\\[\\/\\1\\]","gi");F=F.replace(n,function(G){var H=G.hashCode();s.push({key:H,value:G.replace(/\$/g,"$$$$")});return"@@"+H+"@@"});F=F.replace(/\[url\]([^"]+?)\[\/url]/gi,'<a href="$1">$1</a>'+this.opts.invisibleSpace);F=F.replace(/\[url\='([^'"]+)']([\s\S]+?)\[\/url]/gi,'<a href="$1">$2</a>'+this.opts.invisibleSpace);F=F.replace(/\[url\=([^'"\]]+)]([\s\S]+?)\[\/url]/gi,'<a href="$1">$2</a>'+this.opts.invisibleSpace);F=F.replace(/\[email\]([^"]+?)\[\/email]/gi,'<a href="mailto:$1">$1</a>'+this.opts.invisibleSpace);F=F.replace(/\[email\=([^"\]]+)](.+?)\[\/email]/gi,'<a href="mailto:$1">$2</a>'+this.opts.invisibleSpace);F=F.replace(/\[b\]([\s\S]*?)\[\/b]/gi,"<b>$1</b>");F=F.replace(/\[i\]([\s\S]*?)\[\/i]/gi,"<i>$1</i>");F=F.replace(/\[u\]([\s\S]*?)\[\/u]/gi,"<u>$1</u>");F=F.replace(/\[s\]([\s\S]*?)\[\/s]/gi,"<strike>$1</strike>");F=F.replace(/\[sub\]([\s\S]*?)\[\/sub]/gi,"<sub>$1</sub>");F=F.replace(/\[sup\]([\s\S]*?)\[\/sup]/gi,"<sup>$1</sup>");F=F.replace(/\[img\]([^"]+?)\[\/img\]/gi,'<img src="$1" />');F=F.replace(/\[img='?([^"]*?)'?,'?(left|right)'?\]\[\/img\]/gi,function(H,I,J){var G="float: "+J+";";if(J==="left"){G+="margin: 0 15px 7px 0"}else{G+="margin: 0 0 7px 15px"}return'<img src="'+I+'" style="'+G+'" />'});F=F.replace(/\[img='?([^"]*?)'?,'?(left|right|none)'?,'?(\d+)'?\]\[\/img\]/gi,function(H,J,K,I){var G="float: "+K+"; width: "+I+"px";if(K==="left"){G+="margin: 0 15px 7px 0"}else{G+="margin: 0 0 7px 15px"}return'<img src="'+J+'" style="'+G+'" />'});F=F.replace(/\[img='?([^"]*?)'?\]\[\/img\]/gi,'<img src="$1" />');F=F.replace(/\[size=(\d+)\]([\s\S]*?)\[\/size\]/gi,(function(G,H,I){I=$.trim(I);if(!I.length){I=this.opts.invisibleSpace}return'<span style="font-size: '+H+'pt">'+I+"</span>"}).bind(this));F=F.replace(/\[color=([#a-z0-9]*?)\]([\s\S]*?)\[\/color\]/gi,(function(H,G,I){I=$.trim(I);if(!I.length){I=this.opts.invisibleSpace}return'<span style="color: '+G+'">'+I+"</span>"}).bind(this));F=F.replace(/\[font='?([a-z,\- ]*?)'?\]([\s\S]*?)\[\/font\]/gi,(function(H,G,I){I=$.trim(I);if(!I.length){I=this.opts.invisibleSpace}return'<span style="font-family: '+G+'">'+I+"</span>"}).bind(this));F=F.replace(/\[align=(left|right|center|justify)\]([\s\S]*?)\[\/align\]/gi,'<div style="text-align: $1">$2</div>');F=F.replace(/\[\*\]([\s\S]*?)(?=\[\*\]|\[\/list\])/gi,"<li>$1</li>");F=F.replace(/\[list\]/gi,"<ul>");F=F.replace(/\[list=1\]/gi,'<ul style="list-style-type: decimal">');F=F.replace(/\[list=a\]/gi,'<ul style="list-style-type: lower-latin">');F=F.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">');F=F.replace(/\[\/list\]/gi,"</ul>");F=F.replace(/\[table\]([\S\s]*?)\[\/table\]/gi,function(G,H){return"[table]"+$.trim(H)+"[/table]"});F=F.replace(/\[table\]\n*/gi,'<table border="1" cellspacing="1" cellpadding="1" style="width: 500px;">');F=F.replace(/\[\/table\](\n*)?/gi,function(G,H){if(H){if(H.match(/\n/g).length>2){H=H.replace(/^\n/,"")}return"</table>"+H}return"</table>"});F=F.replace(/\[tr\]\n*/gi,"<tr>");F=F.replace(/\[\/tr\]\n*/gi,"</tr>");F=F.replace(/\[td\]\n*/gi,"<td>");F=F.replace(/\[\/td\]\n*/gi,"</td>");F=F.replace(/<td>([\S\s]*?)<\/td>/gi,function(G,I){var H=$.trim(I);if(!H.length){H="​"}return"<td>"+H+"</td>"});var c=this.wutil.getOption("woltlab.attachmentUrl");var E=this.wutil.getOption("woltlab.attachmentThumbnailUrl");if(c){var C=this.wbbcode._getImageAttachments();F=F.replace(/\[attach=(\d+)\]\[\/attach\]/g,function(G,H,I){H=parseInt(H);if(C[H]!==undefined){return'<img src="'+E.replace(/987654321/,H)+'" class="redactorEmbeddedAttachment redactorDisableResize" data-attachment-id="'+H+'" />'}return G});F=F.replace(/\[attach=(\d+),(left|right|none)\]\[\/attach\]/g,function(H,I,J){I=parseInt(I);if(C[I]!==undefined){var G="";if(J==="left"||J==="right"){G="float: "+J+";";if(J==="left"){G+="margin: 0 15px 7px 0"}else{G+="margin: 0 0 7px 15px"}}G=' style="'+G+'"';return'<img src="'+E.replace(/987654321/,I)+'" class="redactorEmbeddedAttachment redactorDisableResize" data-attachment-id="'+I+'"'+G+" />"}return H});F=F.replace(/\[attach=(\d+),(left|right|none),(\d+)\]\[\/attach\]/g,function(H,J,K,I){J=parseInt(J);if(C[J]!==undefined){var G="width: "+I+"px; max-height: "+C[J].height+"px; max-width: "+C[J].width+"px;";if(K==="left"||K==="right"){G+="float: "+K+";";if(K==="left"){G+="margin: 0 15px 7px 0"}else{G+="margin: 0 0 7px 15px"}}G=' style="'+G+'"';return'<img src="'+c.replace(/987654321/,J)+'" class="redactorEmbeddedAttachment" data-attachment-id="'+J+'"'+G+" />"}return H})}for(var u in __REDACTOR_SMILIES){var j=u.replace(/</g,"<").replace(/>/g,">");var i=new RegExp("(\\s|>|^)"+WCF.String.escapeRegExp(j)+"(?=\\s|<|$)","gi");F=F.replace(i,'$1<img src="'+__REDACTOR_SMILIES[u]+'" class="smiley" alt="'+j+'" />')}F=F.replace(/(javascript):/gi,"$1<span></span>:");F=F.replace(/(\r|\r\n)/g,"\n");var y=[];var B=[];var g=F.split(/(\[(?:\/quote|quote|quote='[^']*?'(?:,'[^']*?')?|quote="[^"]*?"(?:,"[^"]*?")?)\])/i);var d=WCF.getUUID();while(true){var o=false;for(var a=0;a<g.length;a++){var A=g[a];if(A.toLowerCase()==="[/quote]"){o=true;var e="";var m=g.slice(0,a);var b=false;while(m.length){var z=m.pop();e=z+e;if(z.match(/^\[quote/i)){A=e+A;var l=WCF.getUUID();y.push({hashCode:l,content:A.replace(/\$/g,"$$$$")});B.push(l);A="@@"+l+"@@";b=true;break}}if(!b){m=g.slice(0,a);A=d}g=m.concat(A,g.slice(a+1));break}}if(!o){break}}F=g.join("");F=F.replace(new RegExp(d,"g"),"[/quote]");F=F.replace(/\n*$/,"");var v=[];F=F.replace(/(<li>[\s\S]*?<\/li>)/g,function(G){G=$.trim(G).replace(/\n/,"<br>");var H=WCF.getUUID();v.push({key:H,content:G});return H});var f=F.split("\n");F="";for(var a=0,k=f.length;a<k;a++){var r=$.trim(f[a]);if(r.match(/^<([a-z]+)/)||r.match(/<\/([a-z]+)>$/)){if(this.reIsBlock.test(RegExp.$1.toUpperCase())){if(r.match(/^<([a-z]+).*<\/\1>/)){F+=r}else{F+=r+"<br />"}}else{F+="<p>"+r+"</p>"}}else{if(!r){r="<br>"}else{if(r.match(/^@@([0-9\-]+)@@$/)){if(WCF.inArray(RegExp.$1,B)){F+=r;continue}}}F+="<p>"+r+"</p>"}}if(v.length){for(var a=v.length-1;a>=0;a--){F=F.replace(v[a].key,v[a].content)}}if(y.length){var D=function(G){return G.replace(/^['"]/,"").replace(/['"]$/,"")};var q=this;var p=function(G){return G.replace(/\[quote(=['"].+['"])?\]([\S\s]*)\[\/quote\]/gi,function(J,I,L){var P="";var K="";if(I){I=I.substr(1);I=I.split(",");switch(I.length){case 1:P=I[0];break;case 2:P=I[0];K=I[1];break}P=WCF.String.escapeHTML(D($.trim(P)));K=WCF.String.escapeHTML(D($.trim(K)))}var Q='<blockquote class="quoteBox container containerPadding quoteBoxSimple" cite="'+K+'" data-author="'+P+'"><header contenteditable="false"><h3>'+q.wbbcode._buildQuoteHeader(P,K)+'</h3><a class="redactorQuoteEdit"></a></header>';L=$.trim(L);var H="";if(L.length){var O=L.split("\n");for(var N=0;N<O.length;N++){var M=O[N];if(M.length===0){M=q.opts.invisibleSpace}else{if(M.match(/^@@([0-9\-]+)@@$/)){if(WCF.inArray(RegExp.$1,B)){H+=M;continue}}}H+="<div>"+M+"</div>"}}else{H="<div>"+q.opts.invisibleSpace+"</div>"}Q+=H;Q+="</blockquote>";return Q})};for(var a=y.length-1;a>=0;a--){var t=y[a];var w=new RegExp("@@"+t.hashCode+"@@","g");F=F.replace(w,p(t.content))}}if(s.length){for(var a=s.length-1;a>=0;a--){var x=s[a];var w=new RegExp("@@"+x.key+"@@","g");var h=x.value;h=h.replace(/^\[code([^\]]*)\]([\S\s]*)\[\/code\]$/,function(J,Q,L){var K="plain";var O=0;var N="";if(Q){Q=Q.substring(1);Q=Q.split(",");var M=function(S){return S.match(/^\d+$/)};var I=function(S){return(S.indexOf(".")!==-1)};var H=function(S){return(__REDACTOR_CODE_HIGHLIGHTERS[Q[0]]!==undefined)};var G=function(S){return S.replace(/^(["'])(.*)\1$/,"$2")};switch(Q.length){case 1:if(M(Q[0])){O=(parseInt(Q[0])>1)?Q[0]:0}else{if(I(Q[0])){N=G(Q[0])}else{if(H(Q[0])){K=Q[0]}}}break;case 2:if(M(Q[0])){O=(parseInt(Q[0])>1)?Q[0]:0;if(I(Q[1])){N=G(Q[1])}else{if(H(Q[1])){K=Q[1]}}}else{if(H(Q[0])){K=Q[0]}if(I(Q[1])){N=G(Q[1])}}break;case 3:if(H(Q[0])){K=Q[0]}if(M(Q[1])){O=Q[1]}if(I(Q[2])){N=G(Q[2])}break}}L=L.replace(/^\n+/,"").replace(/\n+$/,"").split(/\n/);var R="";for(var P=0;P<L.length;P++){R+="<li>"+L[P]+"</li>"}return'<div class="codeBox container" contenteditable="false" data-highlighter="'+K+'"'+(N?' data-filename="'+WCF.String.escapeHTML(N)+'"':"")+"><div><div><h3>"+__REDACTOR_CODE_HIGHLIGHTERS[K]+(N?": "+WCF.String.escapeHTML(N):"")+'</h3></div><ol start="'+(O>1?O:1)+'">'+R+"</ol></div></div>"});F=F.replace(w,h)}}F=F.replace(/<p><(blockquote|div)/g,"<$1");F=F.replace(/<\/(blockquote|div)><\/p>/g,"</$1>");WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","afterConvertToHtml",{data:F});return F},_pasteBeforeCallback:function(a){var b={1:24,2:22,3:18,4:14,5:12,6:10};console.debug(a);a=a.replace(/<h([1-6])[^>]+>/g,function(c,d){return"[size="+b[d]+"]"});a=a.replace(/<\/h[1-6]>/g,"[/size]");a=a.replace(/<(article|header)[^>]+>/g,"<div>");a=a.replace(/<\/(article|header)>/g,"</div>");a=a.replace(/<(div|p)([^>]+)?><(div|p)([^>]+)?>/g,"<p>");a=a.replace(/<\/(div|p)><\/(div|p)>/g,"</p>");WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","beforePaste",{html:a});return a},_pasteCallback:function(a){console.debug(a);a=a.replace(/\[size=(\d+)\]/g,'<p><span style="font-size: $1pt">');a=a.replace(/\[\/size\]/g,"</span></p>");WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","afterPaste",{html:a});return a;a=a.replace(/<img([^>]+)>/g,function(b,c){b=b.replace(/data-mozilla-paste-image="0"/,'data-mozilla-paste-image="0" style="display:none"');return b});return a},insertAttachment:function(e,c){e=parseInt(e);var a=this.wutil.getOption("woltlab.attachment"+(!c?"Thumbnail":"")+"Url");var d=this.wbbcode._getImageAttachments();if(a&&d[e]!==undefined){var b="";if(c){b=' style="width: '+d[e].width+"px; max-height: "+d[e].height+"px; max-width: "+d[e].width+'px;"'}this.wutil.insertDynamic('<img src="'+a.replace(/987654321/,e)+'" class="redactorEmbeddedAttachment'+(!c?" redactorDisableResize":"")+'" data-attachment-id="'+e+'"'+b+" />","[attach="+e+(c?",none,"+d[e].width:"")+"][/attach]")}else{this.wutil.insertDynamic("[attach="+e+"][/attach]")}},removeAttachment:function(a){if(!this.opts.visual){return}this.$editor.find("img.redactorEmbeddedAttachment").each(function(b,d){var c=$(d);if(c.data("attachmentID")==a){c.remove()}})},_getImageAttachments:function(){var b=this.wutil.getOption("woltlab.attachmentImages")||[];if(b.length){delete this.opts.attachmentImages;return b}var a={imageAttachments:{}};WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","getImageAttachments_"+this.$textarea.wcfIdentify(),a);return a.imageAttachments},_keydownCallback:function(g){switch(g.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;break}this.selection.get();var a=$(this.selection.getCurrent());var f=this.selection.getParent();f=(f)?$(f):f;var l=(f)?f.closest("blockquote.quoteBox",this.$editor.get()[0]):{length:0};switch(g.event.which){case $.ui.keyCode.BACKSPACE:if(this.wutil.isCaret()){if(l.length){var c=true;l.find("div > div").each(function(){if($(this).text().replace(/\u200B/,"").length){c=false;return false}});if(c){var h=window.getSelection();if(h.rangeCount){h.removeAllRanges()}var i=document.createRange();i.selectNode(l[0]);h.addRange(i);g.cancel=true}}}break;case $.ui.keyCode.DELETE:if(this.wutil.isCaret()){if(this.wutil.isEndOfElement(a[0])&&a.next("blockquote").length){var h=window.getSelection();if(h.rangeCount){h.removeAllRanges()}var i=document.createRange();i.selectNode(a.next()[0]);h.addRange(i);g.cancel=true}}break;case $.ui.keyCode.DOWN:if(a.next("blockquote").length){this.caret.setStart(a.next().find("> div > div:first"));g.cancel=true}else{if(f){if(f.next("blockquote").length){this.caret.setStart(f.next().find("> div > div:first"));g.cancel=true}else{if(l.length){var k=a.closest("div",l[0]);if(!k.next().length){if(l.next().length){this.caret.setStart(l.next())}else{this.wutil.setCaretAfter(l)}g.cancel=true}}}}}break;case $.ui.keyCode.ENTER:if(l.length){this.keydown.blockquote=false;this.keydown.enterWithinBlockquote=true}break;case $.ui.keyCode.UP:if(!f||!l.length){return}var k=a.closest("div",l[0]);var b=k.prev();if(b[0].tagName==="DIV"){return}else{if(b[0].tagName==="BLOCKQUOTE"){return}}var j=l.prev();if(j.length===0){this.wutil.setCaretBefore(l)}else{if(j[0].tagName==="BLOCKQUOTE"){this.caret.sendEnd(j.find("> div > div:last"))}else{if($.trim(j.html())==""){j.html(this.opts.invisibleSpace)}this.caret.setEnd(j)}}g.cancel=true;break;case 83:if($.browser.mobile){return}var e=false;if(navigator.platform.match(/^Mac/)){if(g.event.ctrlKey&&g.event.altKey){e=true}}else{if(g.event.altKey){e=true}}if(e){var d={cancel:false};WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","submitEditor_"+this.$textarea.wcfIdentify(),d);if(d.cancel){g.cancel=true}}break}},_keyupCallback:function(a){if(a.event.which!==$.ui.keyCode.BACKSPACE&&a.event.which!==$.ui.keyCode.DELETE){return}this.$editor.find("blockquote").each(function(b,d){var c=$(d);if(!c.children("header").length){c.remove()}})},observeQuotes:function(){var a=this.$editor.find(".redactorQuoteEdit:not(.jsRedactorQuoteEdit)");if(a.length){a.each((function(d,c){var b=$(c);b.addClass("jsRedactorQuoteEdit").click($.proxy(this.wbbcode._observeQuotesClick,this))}).bind(this))}},_observeQuotesClick:function(d){var b=$(d.currentTarget).closest("header");var c=$('<span class="redactor-link-tooltip" />');$('<a href="#">'+WCF.Language.get("wcf.bbcode.quote.edit")+"</a>").click($.proxy(function(f){f.preventDefault();this.wbbcode._openQuoteEditOverlay($(d.currentTarget).closest("blockquote.quoteBox"),false);$(".redactor-link-tooltip").remove()},this)).appendTo(c);var a=b.offset();c.css({left:a.left+"px",top:(a.top+20)+"px"});$(".redactor-link-tooltip").remove();c.appendTo(document.body);this.selection.remove()},observeCodeListings:function(){this.$editor.find(".codeBox:not(.jsRedactorCodeBox)").each((function(a,d){var b=$(d).addClass("jsRedactorCodeBox");var c=$('<div class="redactorEditCodeBox"><div>'+WCF.Language.get("wcf.bbcode.code.edit")+"</div></div>").insertAfter(b.find("> div > div > h3"));c.click((function(){this.wbbcode._handleInsertCode(b,false)}).bind(this))}).bind(this))},_openQuoteEditOverlay:function(a,c){this.modal.load("quote",WCF.Language.get("wcf.bbcode.quote."+(c?"insert":"edit")),400);var b=this.modal.createActionButton(this.lang.get("save"));if(c){this.selection.save();b.click($.proxy(function(){var f=$("#redactorQuoteAuthor").val();var e=WCF.String.escapeHTML($("#redactorQuoteLink").val());this.selection.restore();var d=this.selection.getHtml();if(this.utils.isEmpty(d)){d=""}var g=this.wbbcode.insertQuoteBBCode(f,e,d);if(g!==null){if(!d.length){this.caret.setStart(g.find("> div")[0])}}this.modal.close()},this))}else{$("#redactorQuoteAuthor").val(a.data("author"));$("#redactorQuoteLink").val(WCF.String.unescapeHTML(a.attr("cite")));b.click($.proxy(function(){var d=$("#redactorQuoteAuthor").val();a.data("author",d);a.attr("data-author",d);a.prop("cite",WCF.String.escapeHTML($("#redactorQuoteLink").val()));this.wbbcode._updateQuoteHeader(a);this.modal.close()},this))}this.modal.show()},_updateQuoteHeader:function(b){var c=b.data("author");var a=b.attr("cite");if(a){a=WCF.String.escapeHTML(a)}b.find("> div > header > h3").empty().append(this.wbbcode._buildQuoteHeader(c,a))},insertQuoteBBCode:function(c,h,d,e){var g="[quote]";var a="[/quote]";if(c){if(h){g="[quote='"+c+"','"+h+"']"}else{g="[quote='"+c+"']"}}var l=null;if(this.wutil.inWysiwygMode()){var f=(e)?this.wbbcode.convertToHtml(e):d;var k=WCF.getUUID();var b=this.wbbcode.convertToHtml(g+k+a);b=b.replace(k,f.replace(/^<p>/,"").replace(/<\/p>$/,""));b=b.replace(/^<p>/,"").replace(/<\/p>$/,"");b=b.replace(/<blockquote/,'<blockquote id="'+k+'"');this.insert.html(b,false);l=this.$editor.find("#"+k);if(l.length){var j=l.find("> div");if(j.length==1){if(j[0].innerHTML===""){j[0].innerHTML=this.opts.invisibleSpace}}else{if($.browser.mozilla){var i=l.find("> div > br[type=_moz]");if(i.length){$("<div>"+this.opts.invisibleSpace+"</div>").insertBefore(i);i.remove()}}}l.removeAttr("id");this.wutil.setCaretAfter(l[0])}this.wbbcode.observeQuotes();this.wbbcode.fixBlockLevelElements();this.$toolbar.find("a.re-__wcf_quote").removeClass("redactor-button-disabled")}else{this.wutil.insertAtCaret(g+e+a)}this.wutil.saveSelection();return l},_buildQuoteHeader:function(b,c){var a="";if(!b&&c){b=c;c=""}if(b){if(c){a+='<a href="'+c+'">'}a+=WCF.Language.get("wcf.bbcode.quote.title.javascript",{quoteAuthor:WCF.String.unescapeHTML(b)});if(c){a+="</a>"}}else{a="<small>"+WCF.Language.get("wcf.bbcode.quote.title.clickToSet")+"</small>"}return a},_handleInsertQuote:function(){this.wbbcode._openQuoteEditOverlay(null,true)},_handleInsertCode:function(c,e){this.modal.load("code",WCF.Language.get("wcf.bbcode.code."+(e?"insert":"edit")),400);var a=this.modal.createActionButton(this.lang.get("save")).addClass("buttonPrimary");if(e){this.selection.get();var b=this.selection.getText();this.selection.save();this.modal.show();var i=$("#redactorCodeBox").focus();i.val(b);a.click($.proxy(function(){var p=$("#redactorCodeBox");var m=$("#redactorCodeFilename");var r=$("#redactorCodeHighlighter");var s=$("#redactorCodeLineNumber");var o=p.val().replace(/^\n+/,"").replace(/\n+$/,"");if($.trim(o).length===0){if(!p.next("small.innerError").length){$('<small class="innerError">'+WCF.Language.get("wcf.global.form.error.empty")+"</small>").insertAfter(p)}return}var n=$.trim(m.val().replace(/['"]/g,""));var q="[code="+r.val()+","+s.val()+(n.length?",'"+n+"'":"")+"]";q+=o;q+="[/code]";this.wutil.adjustSelectionForBlockElement();this.wutil.saveSelection();var l=this.wbbcode.convertToHtml(q);this.buffer.set();this.insert.html(l,false);var p=this.$editor.find(".codeBox:not(.jsRedactorCodeBox)");this.wbbcode.observeCodeListings();this.wbbcode.fixBlockLevelElements();p.attr("contenteditable","false");this.caret.setAfter(p);this.modal.close()},this))}else{var g=this.modal.createActionButton(WCF.Language.get("wcf.global.button.delete"));g.click((function(){this.buffer.set();c.remove();this.modal.close()}).bind(this));this.modal.show();var i=$("#redactorCodeBox").focus();var h=$("#redactorCodeFilename");var f=$("#redactorCodeHighlighter");var j=$("#redactorCodeLineNumber");f.val(c.data("highlighter"));h.val(c.data("filename")||"");var d=c.find("> div > ol");j.val(parseInt(d.prop("start")));var k="";d.children("li").each(function(l,m){k+=$(m).text()+"\n"});i.val(k.replace(/^\n+/,"").replace(/\n+$/,""));a.click($.proxy(function(){var m=i.val().replace(/^\n+/,"").replace(/\n+$/,"");if($.trim(m).length===0){if(!i.next("small.innerError").length){$('<small class="innerError">'+WCF.Language.get("wcf.global.form.error.empty")+"</small>").insertAfter(i)}return}var q=f.val();c.data("highlighter",q);c.attr("data-highlighter",q);var n=__REDACTOR_CODE_HIGHLIGHTERS[q];var l=$.trim(h.val().replace(/['"]/g,""));if(l){n+=": "+WCF.String.escapeHTML(l);c.data("filename",l);c.attr("data-filename",l)}else{c.removeAttr("data-filename");c.removeData("filename")}c.data("highlighter",f.val());c.find("> div > div > h3").html(n);var o=c.find("> div > ol").empty();var r=parseInt(j.val());o.prop("start",(r>1?r:1));m=m.split("\n");var p="";for(var s=0;s<m.length;s++){p+="<li>"+WCF.String.escapeHTML(m[s])+"</li>"}o.append($(p));this.modal.close()},this))}},fixBlockLevelElements:function(){var a=(function(d,c){var b="P";if(d.parentElement.tagName==="DIV"&&d.parentElement!==this.$editor[0]){d=d.parentElement;b="DIV"}if(d[c]===null||d[c].tagName!==b){$("<"+b+">"+this.opts.invisibleSpace+"</"+b+">")[(c==="previousElementSibling"?"insertBefore":"insertAfter")](d)}else{if(d.previousElementSibling.tagName===b){if(!d[c].innerHTML.length||d[c].innerHTML.toLowerCase()==="<p></p>"){$(d[c]).html(this.opts.invisibleSpace)}}}}).bind(this);this.$editor.find("blockquote, .codeBox").each((function(b,c){a(c,"previousElementSibling");a(c,"nextElementSibling")}).bind(this))}}};
// wbutton.js
-if(!RedactorPlugins){var RedactorPlugins={}}RedactorPlugins.wbutton=function(){return{_bbcodes:{},init:function(){this._bbcodes={};for(var h=0,e=__REDACTOR_BUTTONS.length;h<e;h++){this.wbutton._addBBCodeButton(__REDACTOR_BUTTONS[h])}var a={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"};var d={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")};var b=this.wutil.getOption("buttons");var g="";for(var h=0,e=b.length;h<e;h++){var c=b[h];if(c=="separator"){this.button.get(g).parent().addClass("separator");continue}var f=this.button.get(c);if(f.length){if(a[c]){this.button.setAwesome(c,a[c])}if(c==="table"&&g){f.parent().insertAfter(this.button.get(g).parent())}}else{this.wbutton._addCoreButton(c,(d[c]?d[c]:null),(a[c]?a[c]:null),g)}g=c}this.button.addCallback(this.button.get("image"),$.proxy(this.wbutton.insertImage,this))},_addCoreButton:function(b,c,a,d){var f={title:(c===null?b:c)};if(b==="subscript"||b==="superscript"){f.command=b}var e=this.button.build(b,f);$("<li />").append(e).insertAfter(this.button.get(d).parent());if(a!==null){this.button.setAwesome(b,a)}},_addBBCodeButton:function(b){var c="__wcf_"+b.name;var a=this.button.add(c,b.label);this.button.addCallback(a,this.wbutton._insertBBCode);this._bbcodes[c]={name:b.name,voidElement:(b.voidElement===true)};if(b.icon.match(/^fa\-[a-z\-]+$/)){this.button.setAwesome(c,b.icon)}else{a.css("background-image","url("+__REDACTOR_ICON_PATH+b.icon+")")}},_insertBBCode:function(a){var d=this._bbcodes[a].name;var b={buttonName:a,cancel:false};WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","insertBBCode_"+d+"_"+this.$textarea.wcfIdentify(),b);if(b.cancel===false){var c=this.selection.getHtml();if(false&&d==="tt"){var e=(this.selection.getParent())?$(this.selection.getParent()):null;if(e&&e.closest("inline.inlineCode",this.$editor.get()[0]).length){this.inline.toggleClass("inlineCode")}else{this.inline.toggleClass("inlineCode")}}else{this.buffer.set();if(this._bbcodes[a].voidElement){this.insert.html(c+this.selection.getMarkerAsHtml()+"["+d+"]",false)}else{this.insert.html("["+d+"]"+c+this.selection.getMarkerAsHtml()+"[/"+d+"]",false)}this.selection.restore()}}event.preventDefault();return false},insertImage:function(){this.image.show()},_insertImage:function(){var d=$("#redactor-image-link-source");var b=d.val().trim();if(b.length){this.buffer.set();var c=$("#redactor-image-align").val();var a="";if(c==="left"||c==="right"){a=' style="float: '+c+'"'}this.insert.html('<img src="'+b+'"'+a+">",false);this.modal.close();this.observe.images()}else{if(!d.next("small.innerError")){$('<small class="innerError">'+WCF.Language.get("wcf.global.form.error.empty")+"</small>").insertAfter(d)}}}}};
+if(!RedactorPlugins){var RedactorPlugins={}}RedactorPlugins.wbutton=function(){return{_bbcodes:{},init:function(){this._bbcodes={};for(var h=0,e=__REDACTOR_BUTTONS.length;h<e;h++){this.wbutton._addBBCodeButton(__REDACTOR_BUTTONS[h])}var a={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"};var d={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")};var b=this.wutil.getOption("buttons");var g="";for(var h=0,e=b.length;h<e;h++){var c=b[h];if(c=="separator"){this.button.get(g).parent().addClass("separator");continue}var f=this.button.get(c);if(f.length){if(a[c]){this.button.setAwesome(c,a[c])}if(c==="table"&&g){f.parent().insertAfter(this.button.get(g).parent())}}else{this.wbutton._addCoreButton(c,(d[c]?d[c]:null),(a[c]?a[c]:null),g)}g=c}this.button.addCallback(this.button.get("image"),$.proxy(this.wbutton.insertImage,this))},_addCoreButton:function(b,c,a,d){var f={title:(c===null?b:c)};if(b==="subscript"||b==="superscript"){f.command=b}var e=this.button.build(b,f);$("<li />").append(e).insertAfter(this.button.get(d).parent());if(a!==null){this.button.setAwesome(b,a)}},_addBBCodeButton:function(b){var c="__wcf_"+b.name;var a=this.button.add(c,b.label);this.button.addCallback(a,this.wbutton._insertBBCode);this._bbcodes[c]={name:b.name,voidElement:(b.voidElement===true)};if(b.icon.match(/^fa\-[a-z\-]+$/)){this.button.setAwesome(c,b.icon)}else{a.css("background-image","url("+__REDACTOR_ICON_PATH+b.icon+")")}},_insertBBCode:function(a){var d=this._bbcodes[a].name;var b={buttonName:a,cancel:false};WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","insertBBCode_"+d+"_"+this.$textarea.wcfIdentify(),b);if(b.cancel===false){var c=this.selection.getHtml();if(false&&d==="tt"){var e=(this.selection.getParent())?$(this.selection.getParent()):null;if(e&&e.closest("inline.inlineCode",this.$editor.get()[0]).length){this.inline.toggleClass("inlineCode")}else{this.inline.toggleClass("inlineCode")}}else{this.buffer.set();if(this.utils.browser("mozilla")&&!c.length){var f=getSelection().getRangeAt(0).startContainer;if(f.nodeType===Node.ELEMENT_NODE&&f.tagName==="P"&&f.innerHTML==="<br>"){f.removeChild(f.children[0])}}if(this._bbcodes[a].voidElement){this.insert.html(c+this.selection.getMarkerAsHtml()+"["+d+"]",false)}else{this.insert.html("["+d+"]"+c+this.selection.getMarkerAsHtml()+"[/"+d+"]",false)}this.selection.restore()}}},insertImage:function(){this.image.show()},_insertImage:function(){var d=$("#redactor-image-link-source");var b=d.val().trim();if(b.length){this.buffer.set();var c=$("#redactor-image-align").val();var a="";if(c==="left"||c==="right"){a=' style="float: '+c+'"'}this.insert.html('<img src="'+b+'"'+a+">",false);this.modal.close();this.observe.images()}else{if(!d.next("small.innerError")){$('<small class="innerError">'+WCF.Language.get("wcf.global.form.error.empty")+"</small>").insertAfter(d)}}}}};
// wfontcolor.js
if(!RedactorPlugins){var RedactorPlugins={}}RedactorPlugins.wfontcolor=function(){return{init:function(){var a=this.button.addDropdown(this.button.get("fontcolor"));this.wfontcolor._createDropdown(a)},_createDropdown:function(h){var b=["#000000","#800000","#8B4513","#2F4F4F","#008080","#000080","#4B0082","#696969","#B22222","#A52A2A","#DAA520","#006400","#40E0D0","#0000CD","#800080","#808080","#FF0000","#FF8C00","#FFD700","#008000","#00FFFF","#0000FF","#EE82EE","#A9A9A9","#FFA07A","#FFA500","#FFFF00","#00FF00","#AFEEEE","#ADD8E6","#DDA0DD","#D3D3D3","#FFF0F5","#FAEBD7","#FFFFE0","#F0FFF0","#F0FFFF","#F0F8FF","#E6E6FA","#FFFFFF"];var e=$('<li class="redactorColorPallet" />');for(var g=0,d=b.length;g<d;g++){var f=b[g];var c=$('<a href="#" title="'+f+'" />').data("color",f).css("background-color",f);e.append(c);c.click($.proxy(this.wfontcolor._onColorPick,this))}var a=$('<a href="#" />').html(this.lang.get("none")).data("color","none");a.click($.proxy(this.wfontcolor._onColorPick,this));e.appendTo(h);$('<li class="dropdownDivider" />').appendTo(h);a.appendTo(h);a.wrap("<li />")},_onColorPick:function(a){a.preventDefault();var b=$(a.currentTarget).data("color");if(b==="none"){this.inline.removeStyleRule("color")}else{this.inline.format("span","style","color: "+b+";")}}}};
// wfontfamily.js
// wupload.js
if(!RedactorPlugins){var RedactorPlugins={}}RedactorPlugins.wupload=function(){return{_boundGlobalUploadEvents:false,_dropArea:{},_timer:null,_isDragging:false,_isFile:false,init:function(){var a=".redactor_"+this.$textarea.wcfIdentify();$(document).on("dragover"+a,$.proxy(this.wupload._dragOver,this));$(document).on("dragleave"+a,$.proxy(this.wupload._dragLeave,this));$(document).on("drop"+a,(function(b){b.preventDefault();this.wupload._revertDropArea(undefined,this.$textarea.wcfIdentify())}).bind(this));if(!this.wupload._boundGlobalUploadEvents){this.wupload._boundGlobalUploadEvents=true;$(document).on("dragend",function(b){b.preventDefault()})}WCF.System.Event.addListener("com.woltlab.wcf.attachment","autoInsert_"+this.$textarea.wcfIdentify(),$.proxy(this.wupload.insertPastedImageAttachment,this))},_dragOver:function(d){d=d.originalEvent;if(!d.dataTransfer||!d.dataTransfer.types){return}var e=false;for(var c in d.dataTransfer){if(/^moz/.test(c)){e=true;break}}this.wupload._isFile=false;if(e){if(d.dataTransfer.types[0]==="application/x-moz-file"){this.wupload._isFile=true}}else{for(var g=0;g<d.dataTransfer.types.length;g++){if(d.dataTransfer.types[g]==="Files"){this.wupload._isFile=true;break}}}if(!this.wupload._isFile){return}this.wupload._isFile=true;d.preventDefault();if(!this.wupload._isDragging){var b=this.$textarea.wcfIdentify();if(this.wupload._dropArea[b]===undefined){this.wupload._dropArea[b]=$('<div class="redactorDropArea">'+WCF.Language.get("wcf.attachment.dragAndDrop.dropHere")+"</div>").hide().appendTo(document.body);this.wupload._dropArea[b].on("dragover",$.proxy(this.wupload._hoverDropArea,this)).on("dragleave",$.proxy(this.wupload._revertDropArea,this)).on("drop",$.proxy(this.wupload._drop,this))}var a=(this.wutil.inWysiwygMode())?this.$editor.getDimensions("outer"):this.$textarea.getDimensions("outer");var f=(this.wutil.inWysiwygMode())?this.$editor.getOffsets("offset"):this.$textarea.getOffsets("offset");this.wupload._dropArea[b].css({height:a.height+"px",left:f.left+"px",lineHeight:a.height+"px",top:f.top+"px",width:a.width+"px"}).show();this.wupload._isDragging=true}d.preventDefault()},_hoverDropArea:function(a){this.wupload._dropArea[this.$textarea.wcfIdentify()].addClass("active").text(WCF.Language.get("wcf.attachment.dragAndDrop.dropNow"))},_revertDropArea:function(c,a){if(!this.wupload._isFile){return}var b=a||this.$textarea.wcfIdentify();this.wupload._dropArea[b].removeClass("active").text(WCF.Language.get("wcf.attachment.dragAndDrop.dropHere"));if(a){this.wupload._dropArea[b].hide()}},_dragLeave:function(){if(!this.wupload._isDragging||!this.wupload._isFile){return}if(this.wupload._timer===null){this.wupload._timer=new WCF.PeriodicalExecuter((function(a){a.stop();if(!this.wupload._isDragging){this.wupload._dropArea[this.$textarea.wcfIdentify()].hide()}}).bind(this),100)}else{this.wupload._timer.resume()}this.wupload._isDragging=false},_drop:function(c){if(!this.wupload._isFile){return}c=c.originalEvent||c;if(c.dataTransfer&&c.dataTransfer.files.length){c.preventDefault();var b=this.$textarea.wcfIdentify();this.wupload._revertDropArea(undefined,b);for(var d=0;d<c.dataTransfer.files.length;d++){var a=c.dataTransfer.files[d];if(a.type){WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","upload_"+b,{file:a})}}}},pasteClipboardUploadMozilla:function(){this.$editor.find("img[data-mozilla-paste-image]").each($.proxy(function(d,g){var f=$(g);var a=f.prop("src").split(",");var e=a[0].split(";")[0].split(":")[1];var c=a[1];var b={blob:WCF.base64toBlob(c,e),uploadID:null};WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","upload_"+this.$textarea.wcfIdentify(),b);f.replaceWith('<span class="redactor-pastedImageFromClipboard-'+b.uploadID+'" />')},this))},insertPastedImageAttachment:function(b){var a=this.$editor.find("span.redactor-pastedImageFromClipboard-"+b.uploadID);a.before(b.attachment);a.remove()}}};
// wutil.js
-if(!RedactorPlugins){var RedactorPlugins={}}RedactorPlugins.wutil=function(){var a="";var b=null;return{_autosaveWorker:null,_range:null,init:function(){this.$textarea.parents("form").submit($.proxy(this.wutil.submit,this));if(this.wutil.getOption("woltlab.autosave").active){this.wutil.autosaveEnable();if(this.wutil.getOption("woltlab.autosave").saveOnInit||this.$textarea.data("saveOnInit")){this.wutil.setOption("woltlab.autosaveOnce",true)}else{this.wutil.autosaveRestore()}}this.wutil.setOption("autosave",false);var c=this.core.destroy;this.core.destroy=(function(){this.wutil.autosaveDisable();c.call(this)}).bind(this)},saveSelection:function(){var c=getSelection();if(c.rangeCount){this.wutil._range=c.getRangeAt(0)}},restoreSelection:function(){if(document.activeElement!==this.$editor[0]){this.$editor.focus()}if(this.wutil._range!==null){var c=window.getSelection();c.removeAllRanges();c.addRange(this.wutil._range);this.wutil._range=null}},clearSelection:function(){this._wutil.range=null},insertAtCaret:function(d){if(this.opts.visual){console.debug("insertAtCaret() failed: Editor is in WYSIWYG-mode.");return false}this.$textarea.focus();var e=this.$textarea.getCaret();if(e==-1){console.debug("insertAtCaret() failed: Source is not input[type=text], input[type=password] or textarea.")}var c=this.$textarea.val();c=c.substr(0,e)+d+c.substr(e);this.$textarea.val(c);return true},insertDynamic:function(c,d){if(this.wutil.inWysiwygMode()){this.insert.html(c,false)}else{if(d===undefined||d===null){d=c}this.wutil.insertAtCaret(d)}},setOption:function(c,d){if(c.indexOf(".")!==-1){c=c.split(".",2);this.opts[c[0]][c[1]]=d}else{this.opts[c]=d}},getOption:function(c){if(c.indexOf(".")!==-1){c=c.split(".",2);if(this.opts[c[0]][c[1]]){return this.opts[c[0]][c[1]]}}else{if(this.opts[c]){return this.opts[c]}}return null},inPlainMode:function(){return !this.opts.visual},inWysiwygMode:function(){return(this.opts.visual)},replaceRangesWith:function(c){getSelection().removeAllRanges();getSelection().addRange(c)},getText:function(){if(this.wutil.inWysiwygMode()){this.code.startSync();var c=this.$textarea.val();this.$textarea.val($.trim(this.wbbcode.convertFromHtml(c)))}var d=$.trim(this.$textarea.val());d=d.replace(/\[\/quote\]\n/g,"[/quote]");return d},isEmptyEditor:function(){if(this.opts.visual){return this.utils.isEmpty(this.$editor.html())}return(!$.trim(this.$textarea.val()))},submit:function(){if(this.wutil.inWysiwygMode()){this.code.startSync();this.$textarea.val($.trim(this.wbbcode.convertFromHtml(this.$textarea.val())))}this.wutil.autosavePurge()},reset:function(){if(this.opts.visual){this.$editor.html("<p>"+this.opts.invisibleSpace+"</p>");this.wutil.saveSelection()}this.$textarea.val("");WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","reset",{wysiwygContainerID:this.$textarea.wcfIdentify()})},autosaveEnable:function(c){if(!this.wutil.getOption("woltlab.autosave").active){this.wutil.setOption("woltlab.autosave",{active:true,key:c})}if(this.wutil._autosaveWorker===null){this.wutil.autosavePurgeOutdated();this.wutil._autosaveWorker=new WCF.PeriodicalExecuter($.proxy(this.wutil.saveTextToStorage,this),15*1000)}return true},saveTextToStorage:function(d){var c=this.wutil.getText();if(a==c&&!d){return}try{localStorage.setItem(this.wutil.getOption("woltlab.autosave").key,JSON.stringify({content:c,timestamp:Date.now()}));a=c;this.wutil.autosaveShowNotice("saved")}catch(f){console.debug("[wutil.saveTextToStorage] Unable to access local storage: "+f.message)}},autosaveDisable:function(){if(!this.wutil.getOption("woltlab.autosave").active){return false}this.wutil._autosaveWorker.stop();this.wutil._autosaveWorker=null;this.wutil.setOption("woltlab.autosave",{active:false,key:""});return true},autosavePurge:function(){try{localStorage.removeItem(this.wutil.getOption("woltlab.autosave").key)}catch(c){console.debug("[wutil.autosavePurge] Unable to access local storage: "+c.message)}},autosaveRestore:function(){var c=this.wutil.getOption("woltlab.autosave");var d=null;try{d=localStorage.getItem(c.key)}catch(f){console.debug("[wutil.autosaveRestore] Unable to access local storage: "+f.message)}try{d=(d===null)?null:JSON.parse(d)}catch(f){d=null}if(d===null||!d.content){return false}if(this.wutil.inWysiwygMode()){this.wutil.setOption("woltlab.originalValue",d.content)}else{this.$textarea.val(d.content)}this.wutil.autosaveShowNotice("restored",{timestamp:d.timestamp});WCF.DOMNodeInsertedHandler.execute();return true},autosaveShowNotice:function(f,h){if(b===null){b=$('<div class="redactorAutosaveNotice"><span class="redactorAutosaveMessage" /></div>');b.appendTo(this.$box);b.on("transitionend webkitTransitionEnd",(function(i){if(i.originalEvent.propertyName!=="opacity"){return}if(b.hasClass("open")){if(b.data("callbackOpen")){b.data("callbackOpen")()}}else{if(b.data("callbackClose")){b.data("callbackClose")()}b.removeData("callbackClose");b.removeData("callbackOpen");b.removeClass("redactorAutosaveNoticeRestore");b.empty();$('<span class="redactorAutosaveMessage" />').appendTo(b)}}).bind(this))}var e="";switch(f){case"restored":$('<span class="icon icon16 fa-info blue jsTooltip" title="'+WCF.Language.get("wcf.message.autosave.restored.version",{date:new Date(h.timestamp).toLocaleString()})+'"></span>').prependTo(b);var g=$('<span class="icon icon16 fa-check green pointer jsTooltip" title="'+WCF.Language.get("wcf.message.autosave.restored.confirm")+'"></span>').appendTo(b);var c=$('<span class="icon icon16 fa-times red pointer jsTooltip" title="'+WCF.Language.get("wcf.message.autosave.restored.revert")+'"></span>').appendTo(b);g.click(function(){b.removeClass("open")});c.click((function(){WCF.System.Confirmation.show(WCF.Language.get("wcf.message.autosave.restored.revert.confirmMessage"),(function(i){if(i==="confirm"){this.wutil.reset();this.wutil.autosavePurge();b.removeClass("open")}}).bind(this))}).bind(this));e=WCF.Language.get("wcf.message.autosave.restored");b.addClass("redactorAutosaveNoticeRestore");var d="";d=WCF.System.Event.addListener("com.woltlab.wcf.redactor","keydown_"+this.$textarea.wcfIdentify(),(function(i){WCF.System.Event.removeListener("com.woltlab.wcf.redactor","keydown_"+this.$textarea.wcfIdentify(),d);setTimeout(function(){g.trigger("click")},3000)}).bind(this));break;case"saved":if(b.hasClass("open")){return}setTimeout(function(){b.removeClass("open")},2000);e=WCF.Language.get("wcf.message.autosave.saved");break}b.children("span.redactorAutosaveMessage").text(e);b.addClass("open")},autosavePurgeOutdated:function(){var h=0;var k=this.wutil.getOption("woltlab.autosave").prefix;var j=k+"_wcf_master";try{h=localStorage.getItem(j)}catch(i){console.debug("[wutil.autosavePurgeOutdated] Unable to access local storage: "+i.message)}if(h===0){return}var c=Date.now()-(7*24*3600*1000);if(h===null||h<c){var g=new RegExp("^"+k+"_");for(var f in localStorage){if(f.match(g)&&f!==j){var d=localStorage.getItem(f);try{d=JSON.parse(d)}catch(i){d={timestamp:0}}if(d===null||!d.timestamp||d.timestamp<c){try{localStorage.removeItem(f)}catch(i){console.debug("[wutil.autosavePurgeOutdated] Unable to access local storage: "+i.message)}}}}try{localStorage.setItem(j,Date.now())}catch(i){console.debug("[wutil.autosavePurgeOutdated] Unable to access local storage: "+i.message)}}},buttonReplace:function(f,d,g,i,h){var c=this.buttonGet(f);var e=this.buttonAddAfter(f,d,g,i,h);if(c.parent().hasClass("separator")){e.parent().addClass("separator")}c.parent().remove();return e},removeZeroWidthSpace:function(c){var d="";for(var g=0,f=c.length;g<f;g++){var e=c.charCodeAt(g).toString(16);if(e!="200b"){d+=c[g]}}return d},getSource:function(){return this.$textarea},getName:function(){return this.$textarea.wcfIdentify()},selectionEndOfEditor:function(){this.focus.setEnd();var c=this.$editor.children(":last")[0];if(c.tagName==="P"){if(c.innerHTML===""){c.remove();c=$(this.opts.emptyHtml).appendTo(this.$editor)[0]}if(c.lastChild.nodeType===Element.TEXT_NODE){this.caret.set(c.lastChild,c.lastChild.length,c.lastChild,c.lastChild.length)}else{this.caret.setEnd(c)}}else{this.wutil.setCaretAfter(c)}this.wutil.saveSelection()},adjustSelectionForBlockElement:function(){if(document.activeElement!==this.$editor[0]){this.wutil.restoreSelection()}if(getSelection().getRangeAt(0).collapsed){var e=getSelection().getRangeAt(0).startContainer;if(e.nodeType===Node.TEXT_NODE&&e.textContent==="\u200b"&&e.parentElement.tagName==="P"&&e.parentElement.parentElement===this.$editor[0]){return}else{var c=$(e).parentsUntil(this.$editor[0]).last();if(c[0]===document.body.parentElement){this.wutil.selectionEndOfEditor()}else{var d=$("<p><br></p>").insertAfter(c);this.caret.setEnd(d)}}}},isCaret:function(){this.selection.get();return this.range.collapsed},isEndOfElement:function(c){this.selection.get();if(!this.wutil.isCaret()){return false}if(this.range.endContainer.nodeType===Element.TEXT_NODE){if(this.range.endOffset<this.range.endContainer.length){return false}}if(!this.wutil.isNodeWithin(this.range.endContainer,c)){return false}var d=this.range.endContainer;while(d!==c){if(d.nextSibling){return false}d=d.parentNode}return true},isNodeWithin:function(e,d){var c=$(e);while(c[0]!==this.$editor[0]){if(c[0]===d){return true}c=c.parent()}return false},containsTag:function(d,c){switch(d.nodeType){case Element.ELEMENT_NODE:if(d.tagName===c){return true}case Element.DOCUMENT_FRAGMENT_NODE:for(var e=0;e<d.childNodes.length;e++){if(this.wutil.containsTag(d.childNodes[e],c)){return true}}return false;break;default:return false;break}},replaceText:function(e){var f=$(document);var c=f.scrollTop();var d=false;if(this.wutil.inWysiwygMode()){this.code.toggle();d=true}this.$textarea.val(e);if(d){this.code.toggle();f.scrollTop(c)}f.trigger("resize")},setCaretBefore:function(c){this.wutil._setCaret(c,true)},setCaretAfter:function(c){this.wutil._setCaret(c,false)},_setCaret:function(d,e){var c=$(this.opts.emptyHtml);c[(e?"insertBefore":"insertAfter")](d);this.caret.setEnd(c[0])},fixDOM:function(){var f=this.$editor[0].childNodes[0];var c=f;var d=null;while(c){f=c;c=f.nextSibling;if(f.nodeType===Element.ELEMENT_NODE){if(this.reIsBlock.test(f.tagName)){d=null}else{if(d===null){d=$("<p />").insertBefore(f)}d.append(f)}}else{if(f.nodeType===Element.TEXT_NODE){if(d===null){if(c){if(c.nodeType===Element.ELEMENT_NODE&&c.tagName==="P"&&c.innerHTML==="\u200B"){var e=c.nextSibling;this.$editor[0].removeChild(c);c=e}}d=$("<p />").insertBefore(f)}d.append(f)}}}}}};
+if(!RedactorPlugins){var RedactorPlugins={}}RedactorPlugins.wutil=function(){var b="";var c=null;var a=false;var d=null;return{_autosaveWorker:null,_range:null,init:function(){this.$textarea.parents("form").submit($.proxy(this.wutil.submit,this));if(this.wutil.getOption("woltlab.autosave").active){this.wutil.autosaveEnable();if(this.wutil.getOption("woltlab.autosave").saveOnInit||this.$textarea.data("saveOnInit")){this.wutil.setOption("woltlab.autosaveOnce",true)}else{this.wutil.autosaveRestore()}}this.wutil.setOption("autosave",false);var e=this.core.destroy;this.core.destroy=(function(){this.wutil.autosaveDisable();e.call(this)}).bind(this)},saveSelection:function(){var e=getSelection();if(e.rangeCount){this.wutil._range=e.getRangeAt(0)}},restoreSelection:function(){if(document.activeElement!==this.$editor[0]){this.$editor.focus()}if(this.wutil._range!==null){var e=window.getSelection();e.removeAllRanges();e.addRange(this.wutil._range);this.wutil._range=null}},clearSelection:function(){this._wutil.range=null},insertAtCaret:function(f){if(this.opts.visual){console.debug("insertAtCaret() failed: Editor is in WYSIWYG-mode.");return false}this.$textarea.focus();var g=this.$textarea.getCaret();if(g==-1){console.debug("insertAtCaret() failed: Source is not input[type=text], input[type=password] or textarea.")}var e=this.$textarea.val();e=e.substr(0,g)+f+e.substr(g);this.$textarea.val(e);return true},insertDynamic:function(e,f){if(this.wutil.inWysiwygMode()){this.insert.html(e,false)}else{if(f===undefined||f===null){f=e}this.wutil.insertAtCaret(f)}},setOption:function(e,f){if(e.indexOf(".")!==-1){e=e.split(".",2);this.opts[e[0]][e[1]]=f}else{this.opts[e]=f}},getOption:function(e){if(e.indexOf(".")!==-1){e=e.split(".",2);if(this.opts[e[0]][e[1]]){return this.opts[e[0]][e[1]]}}else{if(this.opts[e]){return this.opts[e]}}return null},inPlainMode:function(){return !this.opts.visual},inWysiwygMode:function(){return(this.opts.visual)},replaceRangesWith:function(e){getSelection().removeAllRanges();getSelection().addRange(e)},getText:function(){if(this.wutil.inWysiwygMode()){this.code.startSync();var e=this.$textarea.val();this.$textarea.val($.trim(this.wbbcode.convertFromHtml(e)))}var f=$.trim(this.$textarea.val());f=f.replace(/\[\/quote\]\n/g,"[/quote]");return f},isEmptyEditor:function(){if(this.opts.visual){return this.utils.isEmpty(this.$editor.html())}return(!$.trim(this.$textarea.val()))},submit:function(){if(this.wutil.inWysiwygMode()){this.code.startSync();this.$textarea.val($.trim(this.wbbcode.convertFromHtml(this.$textarea.val())))}this.wutil.autosavePurge()},reset:function(){if(this.opts.visual){this.$editor.html("<p>"+this.opts.invisibleSpace+"</p>");this.wutil.saveSelection()}this.$textarea.val("");WCF.System.Event.fireEvent("com.woltlab.wcf.redactor","reset",{wysiwygContainerID:this.$textarea.wcfIdentify()})},autosaveEnable:function(e){if(!this.wutil.getOption("woltlab.autosave").active){this.wutil.setOption("woltlab.autosave",{active:true,key:e})}if(this.wutil._autosaveWorker===null){this.wutil.autosavePurgeOutdated();this.wutil._autosaveWorker=new WCF.PeriodicalExecuter((function(f){this.wutil.saveTextToStorage(false)}).bind(this),15*1000)}return true},saveTextToStorage:function(g){var f=this.wutil.getText();if(b==f&&!g){return}try{localStorage.setItem(this.wutil.getOption("woltlab.autosave").key,JSON.stringify({content:f,timestamp:Date.now()}));b=f;a=true;if(d===null){d=new WCF.PeriodicalExecuter((function(e){if(a===false){e.stop();d=null;return}this.wutil.autosaveShowNotice("saved");a=false}).bind(this),120*1000)}}catch(h){console.debug("[wutil.saveTextToStorage] Unable to access local storage: "+h.message)}},autosaveDisable:function(){if(!this.wutil.getOption("woltlab.autosave").active){return false}this.wutil._autosaveWorker.stop();this.wutil._autosaveWorker=null;this.wutil.setOption("woltlab.autosave",{active:false,key:""});return true},autosavePurge:function(){try{localStorage.removeItem(this.wutil.getOption("woltlab.autosave").key)}catch(f){console.debug("[wutil.autosavePurge] Unable to access local storage: "+f.message)}},autosaveRestore:function(){var f=this.wutil.getOption("woltlab.autosave");var g=null;try{g=localStorage.getItem(f.key)}catch(h){console.debug("[wutil.autosaveRestore] Unable to access local storage: "+h.message)}try{g=(g===null)?null:JSON.parse(g)}catch(h){g=null}if(g===null||!g.content){return false}if(this.wutil.inWysiwygMode()){this.wutil.setOption("woltlab.originalValue",g.content)}else{this.$textarea.val(g.content)}this.wutil.autosaveShowNotice("restored",{timestamp:g.timestamp});WCF.DOMNodeInsertedHandler.execute();return true},autosaveShowNotice:function(h,j){if(c===null){c=$('<div class="redactorAutosaveNotice"><span class="redactorAutosaveMessage" /></div>');c.appendTo(this.$box);c.on("transitionend webkitTransitionEnd",(function(k){if(k.originalEvent.propertyName!=="opacity"){return}if(c.hasClass("open")){if(c.data("callbackOpen")){c.data("callbackOpen")()}}else{if(c.data("callbackClose")){c.data("callbackClose")()}c.removeData("callbackClose");c.removeData("callbackOpen");c.removeClass("redactorAutosaveNoticeRestore");c.empty();$('<span class="redactorAutosaveMessage" />').appendTo(c)}}).bind(this))}var g="";switch(h){case"restored":$('<span class="icon icon16 fa-info blue jsTooltip" title="'+WCF.Language.get("wcf.message.autosave.restored.version",{date:new Date(j.timestamp).toLocaleString()})+'"></span>').prependTo(c);var i=$('<span class="icon icon16 fa-check green pointer jsTooltip" title="'+WCF.Language.get("wcf.message.autosave.restored.confirm")+'"></span>').appendTo(c);var e=$('<span class="icon icon16 fa-times red pointer jsTooltip" title="'+WCF.Language.get("wcf.message.autosave.restored.revert")+'"></span>').appendTo(c);i.click(function(){c.removeClass("open")});e.click((function(){WCF.System.Confirmation.show(WCF.Language.get("wcf.message.autosave.restored.revert.confirmMessage"),(function(k){if(k==="confirm"){this.wutil.reset();this.wutil.autosavePurge();c.removeClass("open")}}).bind(this))}).bind(this));g=WCF.Language.get("wcf.message.autosave.restored");c.addClass("redactorAutosaveNoticeRestore");var f="";f=WCF.System.Event.addListener("com.woltlab.wcf.redactor","keydown_"+this.$textarea.wcfIdentify(),(function(k){WCF.System.Event.removeListener("com.woltlab.wcf.redactor","keydown_"+this.$textarea.wcfIdentify(),f);setTimeout(function(){i.trigger("click")},3000)}).bind(this));break;case"saved":if(c.hasClass("open")){return}setTimeout(function(){c.removeClass("open")},2000);g=WCF.Language.get("wcf.message.autosave.saved");break}c.children("span.redactorAutosaveMessage").text(g);c.addClass("open")},autosavePurgeOutdated:function(){var j=0;var m=this.wutil.getOption("woltlab.autosave").prefix;var l=m+"_wcf_master";try{j=localStorage.getItem(l)}catch(k){console.debug("[wutil.autosavePurgeOutdated] Unable to access local storage: "+k.message)}if(j===0){return}var f=Date.now()-(7*24*3600*1000);if(j===null||j<f){var i=new RegExp("^"+m+"_");for(var h in localStorage){if(h.match(i)&&h!==l){var g=localStorage.getItem(h);try{g=JSON.parse(g)}catch(k){g={timestamp:0}}if(g===null||!g.timestamp||g.timestamp<f){try{localStorage.removeItem(h)}catch(k){console.debug("[wutil.autosavePurgeOutdated] Unable to access local storage: "+k.message)}}}}try{localStorage.setItem(l,Date.now())}catch(k){console.debug("[wutil.autosavePurgeOutdated] Unable to access local storage: "+k.message)}}},buttonReplace:function(h,f,i,k,j){var e=this.buttonGet(h);var g=this.buttonAddAfter(h,f,i,k,j);if(e.parent().hasClass("separator")){g.parent().addClass("separator")}e.parent().remove();return g},removeZeroWidthSpace:function(e){var f="";for(var i=0,h=e.length;i<h;i++){var g=e.charCodeAt(i).toString(16);if(g!="200b"){f+=e[i]}}return f},getSource:function(){return this.$textarea},getName:function(){return this.$textarea.wcfIdentify()},selectionEndOfEditor:function(){this.focus.setEnd();var e=this.$editor.children(":last")[0];if(e.tagName==="P"){if(e.innerHTML===""){e.remove();e=$(this.opts.emptyHtml).appendTo(this.$editor)[0]}if(e.lastChild.nodeType===Element.TEXT_NODE){this.caret.set(e.lastChild,e.lastChild.length,e.lastChild,e.lastChild.length)}else{this.caret.setEnd(e)}}else{this.wutil.setCaretAfter(e)}this.wutil.saveSelection()},adjustSelectionForBlockElement:function(){if(document.activeElement!==this.$editor[0]){this.wutil.restoreSelection()}if(getSelection().getRangeAt(0).collapsed){var g=getSelection().getRangeAt(0).startContainer;if(g.nodeType===Node.TEXT_NODE&&g.textContent==="\u200b"&&g.parentElement.tagName==="P"&&g.parentElement.parentElement===this.$editor[0]){return}else{var e=$(g).parentsUntil(this.$editor[0]).last();if(e[0]===document.body.parentElement){this.wutil.selectionEndOfEditor()}else{var f=$("<p><br></p>").insertAfter(e);this.caret.setEnd(f)}}}},isCaret:function(){this.selection.get();return this.range.collapsed},isEndOfElement:function(e){this.selection.get();if(!this.wutil.isCaret()){return false}if(this.range.endContainer.nodeType===Element.TEXT_NODE){if(this.range.endOffset<this.range.endContainer.length){return false}}if(!this.wutil.isNodeWithin(this.range.endContainer,e)){return false}var f=this.range.endContainer;while(f!==e){if(f.nextSibling){return false}f=f.parentNode}return true},isNodeWithin:function(g,f){var e=$(g);while(e[0]!==this.$editor[0]){if(e[0]===f){return true}e=e.parent()}return false},containsTag:function(f,e){switch(f.nodeType){case Element.ELEMENT_NODE:if(f.tagName===e){return true}case Element.DOCUMENT_FRAGMENT_NODE:for(var g=0;g<f.childNodes.length;g++){if(this.wutil.containsTag(f.childNodes[g],e)){return true}}return false;break;default:return false;break}},replaceText:function(g){var h=$(document);var e=h.scrollTop();var f=false;if(this.wutil.inWysiwygMode()){this.code.toggle();f=true}this.$textarea.val(g);if(f){this.code.toggle();h.scrollTop(e)}h.trigger("resize")},setCaretBefore:function(e){this.wutil._setCaret(e,true)},setCaretAfter:function(e){this.wutil._setCaret(e,false)},_setCaret:function(f,g){var e=$(this.opts.emptyHtml);e[(g?"insertBefore":"insertAfter")](f);this.caret.setEnd(e[0])},fixDOM:function(){var h=this.$editor[0].childNodes[0];var e=h;var f=null;while(e){h=e;e=h.nextSibling;if(h.nodeType===Element.ELEMENT_NODE){if(this.reIsBlock.test(h.tagName)){f=null}else{if(f===null){f=$("<p />").insertBefore(h)}f.append(h)}}else{if(h.nodeType===Element.TEXT_NODE){if(f===null){if(e){if(e.nodeType===Element.ELEMENT_NODE&&e.tagName==="P"&&e.innerHTML==="\u200B"){var g=e.nextSibling;this.$editor[0].removeChild(e);e=g}}f=$("<p />").insertBefore(h)}f.append(h)}}}}}};