/*
* XenForo bb_code_edit.min.js
* Copyright 2010-2019 XenForo Ltd.
* Released under the XenForo License Agreement: http://xenforo.com/license-agreement
*/
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(d,k,n){d instanceof String&&(d=String(d));for(var p=d.length,b=0;b<p;b++){var c=d[b];if(k.call(n,c,b,d))return{i:b,v:c}}return{i:-1,v:void 0}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(d,k,n){d!=Array.prototype&&d!=Object.prototype&&(d[k]=n.value)};
$jscomp.getGlobal=function(d){return"undefined"!=typeof window&&window===d?d:"undefined"!=typeof global&&null!=global?global:d};$jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(d,k,n,p){if(k){n=$jscomp.global;d=d.split(".");for(p=0;p<d.length-1;p++){var b=d[p];b in n||(n[b]={});n=n[b]}d=d[d.length-1];p=n[d];k=k(p);k!=p&&null!=k&&$jscomp.defineProperty(n,d,{configurable:!0,writable:!0,value:k})}};
$jscomp.polyfill("Array.prototype.find",function(d){return d?d:function(d,n){return $jscomp.findInternal(this,d,n).v}},"es6","es3");
!function(d,k,n,p){XenForo.BbCodeWysiwygEditor=function(b){this.__construct(b)};XenForo.BbCodeWysiwygEditor.prototype={__construct:function(b){this.$textarea=b;this.options=b.data("options")||{};this.dialogUrl=b.data("dialog-url")?XenForo.canonicalizeUrl(b.data("dialog-url"),XenForo.ajaxBaseHref):"index.php?editor/dialog";this.autoSaveUrl=b.data("auto-save-url");this.autoCompleteUrl=b.data("ac-url")||XenForo.AutoComplete.getDefaultUrl();this.pasteImageCounter=1;var c=b.attr("id");c&&(c=XenForo.BbCodeWysiwygEditor_EXTEND[c])&&
(this.options="function"==typeof c?c(this.options,this):d.extend(this.options,c));c=this._adjustButtonConfig(this.getButtonConfig(),this.options.buttons||{});var a=this.getExecHandlers(),e=b.data("css-url");this.editorConfig=d.extend({direction:d("html").attr("dir")||"ltr",formattingTags:[],source:!1,iframe:!0,iframeBase:XenForo.baseUrl(),lang:"xf",buttons:c.buttons,css:e?XenForo.canonicalizeUrl(e,XenForo.ajaxBaseHref):!1,buttonsCustom:c.buttonsCustom,execCommandHandler:a,modal_link:{url:this.dialogUrl+
"&dialog=link"},modal_image:{url:this.dialogUrl+"&dialog=image"},observeImages:!1,allowJustify:!1,cleanupFontTags:!1,convertLinks:!1,modalCreateCallback:d.context(this,"modalCreateCallback"),callback:d.context(this,"editorInit"),pastePreventCallback:d.context(this,"pastePreventCallback"),pasteManipulateCallback:d.context(this,"pasteManipulateCallback"),pasteCleanUpCallback:d.context(this,"pasteCleanUpCallback"),insertHtmlCallback:d.context(this,"insertHtmlCallback")},this.options.editorOptions||{});
d(n).triggerHandler("EditorInit",{editor:this,config:this.editorConfig,$textarea:b});b.css("visibility","").show();b.redactor(this.editorConfig)},getButtonConfig:function(){var b=this,c=[["switchmode"],["removeformat"]],a=this.options.buttonConfig;a&&!a.basic||c.push(["bold","italic","underline"]);a&&!a.extended||c.push(["fontcolor","fontsize","fontfamily"]);a&&!a.link||c.push(["createlink","unlink"]);a&&!a.align||c.push(["alignment"]);!a||a.list?c.push(["unorderedlist","orderedlist","outdent","indent"]):
a.indent&&c.push(["outdent","indent"]);var e=[];a&&!a.smilies||e.push(["smilies"]);a&&!a.image||e.push("image");a&&!a.media||e.push("media");a&&!a.block||e.push("insert");e.length&&c.push(e);e=[];this.options.bbCodes&&d.each(this.options.bbCodes,function(b,c){a&&!a[b]||e.push("custom_"+b)});e.length&&c.push(e);this.autoSaveUrl&&c.push(["draft"]);c.push(["undo","redo"]);var g=function(b,a,c){b.focus();a=d(b.analyzeSelection().selectedEls);a.find("[style]").css("font-size","");a.filter("[style]").css("font-size",
"");b.execCommand("fontsize",c)},f=function(b,a,c){b.focus();a=d(b.analyzeSelection().selectedEls);a.find("[style]").css("font-family","");a.filter("[style]").css("font-family","");b.execCommand("fontname",c)},h={},m={};d.each({Arial:"arial,helvetica,sans-serif","Book Antiqua":"'book antiqua',palatino,serif","Courier New":"'courier new',courier,monospace",Georgia:"georgia,palatino,serif",Tahoma:"tahoma,arial,helvetica,sans-serif","Times New Roman":"'times new roman',times,serif","Trebuchet MS":"'trebuchet ms',geneva,sans-serif",
Verdana:"verdana,geneva,sans-serif"},function(b,a){h[b]={title:b,callback:f,style:"font-family: "+a}});d.each({1:"9px",2:"10px",3:"12px",4:"15px",5:"18px",6:"22px",7:"26px"},function(b,a){m[b]={title:b,callback:g,style:"font-size: "+a}});var l={switchmode:{title:this.getText("switch_mode_bb"),callback:d.context(this,"wysiwygToBbCode")},removeformat:{title:this.getText("remove_formatting"),exec:"removeformat"},fontsize:{title:this.getText("font_size"),func:"show",dropdown:m},fontfamily:{title:this.getText("font_family"),
func:"show",dropdown:h},smilies:{title:this.getText("smilies"),callback:d.context(this,"toggleSmilies")},createlink:{title:this.getText("link"),callback:d.context(this,"getLinkModal")},unlink:{title:this.getText("unlink"),exec:"unlink"},image:{title:this.getText("image"),callback:d.context(this,"getImageModal")},media:{title:this.getText("media"),callback:d.context(this,"getMediaModal")},draftsave:{title:this.getText("save_draft"),callback:d.proxy(function(){this.saveDraft(!0);this.api.focus()},this),
className:"icon saveDraft"},draftdelete:{title:this.getText("delete_draft"),callback:d.proxy(function(){this.saveDraft(!0,!0);this.api.focus()},this),className:"icon deleteDraft"},draft:{title:this.getText("drafts"),func:"show",dropdown:{}},undo:{title:this.getText("undo"),exec:"undo"},redo:{title:this.getText("redo"),exec:"redo"},alignment:{title:this.getText("alignment"),func:"show",dropdown:{alignleft:{title:this.getText("align_left"),exec:"JustifyLeft",className:"icon alignLeft"},aligncenter:{title:this.getText("align_center"),
exec:"JustifyCenter",className:"icon alignCenter"},alignright:{title:this.getText("align_right"),exec:"JustifyRight",className:"icon alignRight"}}},insertquote:{title:this.getText("quote"),callback:function(a){b.wrapSelectionInHtml(a,"[QUOTE]","[/QUOTE]",!0)},className:"icon quote"},insertspoiler:{title:this.getText("spoiler"),callback:d.context(this,"getSpoilerModal"),className:"icon spoiler"},insertcode:{title:this.getText("code"),callback:d.context(this,"getCodeModal"),className:"icon code"},insert:{title:this.getText("insert"),
func:"show",dropdown:{}}};l.draft.dropdown={save:l.draftsave,"delete":l.draftdelete};l.insert.dropdown={quote:l.insertquote,spoiler:l.insertspoiler,code:l.insertcode,deleted:{title:this.getText("deleted"),exec:"StrikeThrough",className:"icon strikethrough"}};this.options.bbCodes&&d.each(this.options.bbCodes,function(a,c){var d=a.toUpperCase();l["custom_"+a]={title:c.title,callback:function(a){"yes"==c.hasOption?b.wrapSelectionInHtml(a,"["+d+"=]","[/"+d+"]",!0):b.wrapSelectionInHtml(a,"["+d+"]","[/"+
d+"]",!0)}}});return{buttons:c,buttonsCustom:l}},_adjustButtonConfig:function(b,c){var a=this,d=[],g;for(g in c)c.hasOwnProperty(g)&&function(e){var f=c[e];b.buttonsCustom[e]={title:a.getText(e,f.title),callback:function(b){if(f.exec)b.execCommand(f.exec);else if(f.tag){var c=f.tag;a.wrapSelectionInHtml(b,"["+c+"]","[/"+c+"]",!0)}}};d.push(e)}(g);d.length&&b.buttons.push(d);return b},getExecHandlers:function(){return{}},editorInit:function(b){this.api=b;var c=this,a=b.$editor,e=a.closest("body"),
g=a.closest("html");d.browser.msie&&(e.click(function(a){a.stopPropagation()}),g.click(function(){b.focus();b.getSelection().collapse(1)}));a.on("cut copy",d.context(this,"editorCutCopyCallback"));d.each(["switchmode","removeformat"],function(a,c){a=b.getBtn(c);c=a.closest(".redactor_btn_group");c.length||(c=a.parent());c.addClass("redactor_btn_right")});a.on("click","img",function(a){b.focus();if(d(this).hasClass("mceSmilie")||d(this).hasClass("mceSmilieSprite")||d(this).hasClass("attachFull")||
d(this).hasClass("attachThumb"))a.preventDefault();else{a=0;for(var e=this;e.previousSibling;)a++,e=e.previousSibling;b.setSelection(this.parentNode,a,this.parentNode,a+1);c.getImageModal(b)}});a.on("click","a",function(a){a.preventDefault()});this.initFocusWatch();this.initPlaceholder();this.initElastic();this.initDragDrop();this.initAutoComplete();this.autoSaveUrl&&setTimeout(function(){c.initAutoSave()},0);this.$textarea.closest("form").submit(function(){b.syncCode()})},editorCutCopyCallback:function(b){var c=
this.api,a=c.$editor,e=c.analyzeSelection();if(!e.isCollapsed){var g=c.getSelectedHtml();g=g.replace(/<p/gi,'<div data-redactor="1"').replace(/<\/p>/gi,"</div>");c.browser("msie")||(g=g.replace(/<(p|div)[^>]><\/(p|div)>/gi,""));g=g.replace(/<font/gi,'<font data-redactor="1"');var f=d('<div data-redactor-wrapper="1" />').html(g).css({position:"absolute",left:"-9999px"});g.match(/<(article|blockquote|dd|div|dl|fieldset|form|h\d|header|hr|ol|p|pre|section|table|ul)/)||(e.$commonAncestor.parents().addBack().filter("b, strong, i, em, u, s, span, strike, font").each(function(){f.append(d(this.cloneNode(!1)).append(f[0].childNodes))}),
g.match(/^\s*<li/)&&e.$commonAncestor.parents().addBack().filter("ul, ol").first().each(function(){f.append(d(this.cloneNode(!1)).append(f[0].childNodes))}));"cut"==b.type&&(c.pasteHtmlAtCaret(""),c.formatEmpty());c.saveSelection();a.append(f);b=c.getSelection();try{b.selectAllChildren(f.get(0))}catch(h){this.api.document.createRange&&b.removeAllRanges&&b.addRange?(a=this.api.document.createRange(),a.selectNode(f.get(0)),b.removeAllRanges(),b.addRange(a)):b.moveToElementText&&(b.moveToElementText(f.get(0)),
b.select())}setTimeout(function(){f.remove();c.restoreSelection()},0)}},initFocusWatch:function(){var b=this.api,c=this,a;b.$editor.on("focus click",function(c){a&&(clearTimeout(a),a=null);b.$box.addClass("focused");d(b.$box[0].ownerDocument).trigger("HideAllMenus")});b.$editor.on("blur",function(c){a=setTimeout(function(){b.$box.removeClass("focused")},200)});b.$editor.on("focus click keypress",function(){c.editorActivated||(b.$box.addClass("activated"),c.editorActivated=!0)});if(b.isMobile(!0)){var e=
k.innerHeight;d(k).on("resize",function(){b.$box.hasClass("focused")&&k.innerHeight<e&&setTimeout(function(){if(0==d(k).scrollTop()){var a=b.getFocus()[0];a&&(b.$editor[0].scrollIntoView(),a.scrollIntoView?a.scrollIntoView():a.parentNode.scrollIntoView())}},50);e=k.innerHeight})}},initPlaceholder:function(){if(this.options.placeholder){var b=this.api,c=this;this.$placeholder||(this.$placeholder=d('<div class="placeholder" />').append(d("<span />").text(this.getText(this.options.placeholder))),b.$content.before(this.$placeholder),
this.$placeholder.click(function(){b.focus()}));this.placeholderVisible=!1;b.$editor.on("focus click keydown",function(){c.placeholderVisible&&(c.$placeholder.hide(),c.placeholderVisible=!1)});b.$editor.html().match(/^$|(^\s*<p>(\s| |<br\s*\/?>)*<\/p>\s*$)/i)&&(this.$placeholder.show(),this.placeholderVisible=!0)}},initElastic:function(){var b=this.api,c=b.$box.find("iframe"),a=d(k).height()-200,e=b.$el.outerHeight(),g=b.$editor[0],f=0,h=d.browser.msie&&9>d.browser.version;c.closest(".xenOverlay").length&&
(a-=175);a=Math.max(a,e);this.minHeight=e;this.maxHeight=a;if(b.isMobile(!0)){var m=function(){var a=b.$box.width();a&&d(g.ownerDocument.documentElement).width(a)};m();b.$editor.on("focus",m);d(k).on("orientationchange resize",function(){setTimeout(m,0)});b.$editor.addClass("noElastic");c.height(Math.max(Math.min(175,k.innerHeight/2),e))}else{var l=function(){if(c){b.$editor.css("min-height","");var m=h?g.scrollHeight:Math.min(g.offsetHeight,g.scrollHeight);b.$editor.css("min-height",e-1);if(m<g.clientHeight||
d.browser.msie)m+=22;m<e?m=e:m>a&&(m=a);m!=f&&(h||(f<m&&m==a?b.$editor.css("overflow-y",""):f==a&&m<a&&b.$editor.css("overflow-y","hidden")),c.height(m),f=m)}};var q;b.$editor.on("paste change keydown focus click drop",function(){q||(q=setTimeout(function(){q=null;l()},100))});b.$editor.data("xenForoElastic",l);h||b.$editor.css("overflow-y","hidden");if(!b.browser("msie"))b.$editor.on("drop",function(a){b.$editor.css("display","block");setTimeout(function(){b.$editor.css("display","")},0)});l();setTimeout(l,
250);this.watchImagesElastic();d(k).focus(l)}},triggerElastic:function(){if(this.$textarea.data("redactor")){var b=this.api.$editor.data("xenForoElastic");b&&b()}},watchImagesElastic:function(b){b=!1===b||"undefined"==typeof b?this.api.$editor:d(b);var c,a=this,e=function(){c&&clearTimeout(c);c=setTimeout(function(){a.triggerElastic()},100)};b.find("img").one("load",e);b.filter("img").one("load",e)},resetEditor:function(b,c){if(this.$textarea.data("redactor")){var a=this.api;b||(b=a.opts.emptyHtml);
a.setCode(b,!1);a.observeFormatting();this.resetAutoSave();this.initPlaceholder();a.$box.find(".redactor_smilies").hide();a.$box.removeClass("activated");this.editorActivated=!1;(b=a.$editor.data("xenForoElastic"))&&b();c&&this.blurEditor()}},blurEditor:function(){if(this.$textarea.data("redactor")){var b=this.api,c=b.$editor;b.opts.iframe&&c[0]&&(b=c[0].ownerDocument)&&(b.defaultView||b.parentWindow).focus();d.browser.msie||c.blur()}},initDragDrop:function(){if(!this.api.isMobile(!0)&&!this.$textarea.hasClass("NoAttachment")){var b=
this.api,c=function(){f.removeClass("hover")},a=b.$box.closest("form").find(".AttachmentUploader"),e=0<a.length,g,f=d('<div class="redactor_editor_drop" />');f.append(d("<span />").text(this.getText(e?"drop_files_here_to_upload":"uploads_are_not_available"))).appendTo(b.$box);e||f.addClass("dragDisabled");var h=function(a){a=a.originalEvent.dataTransfer;if(!a||"undefined"==typeof a.files||a.types&&(-1==d.inArray("Files",a.types)||"text/x-moz-url"==a.types[0]))return!1;a.dropEffect="copy";return!0};
d([n,b.document]).on("dragover",function(a){h(a)&&(f.addClass("hover"),clearTimeout(g),g=setTimeout(c,200))});f.on("dragover",function(a){h(a)&&a.preventDefault()});f.on("drop",function(b){b.preventDefault();clearTimeout(g);c();if(e){b=b.originalEvent.dataTransfer;var f=function(b,c){try{var e=new FormData;e.append("upload",b);e.append("_xfToken",XenForo._csrfToken);e.append("_xfNoRedirect","1");a.find(".HiddenInput").each(function(){var a=d(this);e.append(a.data("name"),a.data("value"))})}catch(u){return}d.ajax({url:a.data("action"),
method:"POST",dataType:"json",data:e,processData:!1,contentType:!1}).done(function(b){XenForo.hasResponseError(b)||a.trigger({type:"AttachmentUploaded",ajaxData:b})}).fail(function(a){try{var b=d.parseJSON(a.responseText);b&&XenForo.hasResponseError(b)}catch(v){}}).always(function(){c&&c()})};if(b&&b.files&&b.files.length){var m=b.files,h=0,k=function(){var a=m[h];a&&(h++,f(a,k))};k()}}})}},initAutoComplete:function(){if(!this.$textarea.hasClass("NoAutoComplete")){var b=this.api.$editor,c=b[0].ownerDocument,
a=this,e,g=function(){e||(e=setTimeout(function(){a.acResults.hideResults();e=null},200))};this.acVisible=!1;this.acResults=new XenForo.AutoCompleteResults({onInsert:d.context(this,"insertAutoComplete")});d(c.defaultView||c.parentWindow).on("scroll",g);b.on("click blur",g);b.on("keydown",function(b){var c=!0,d=a.acResults;if(d.isVisible()){switch(b.keyCode){case 40:d.selectResult(1);break;case 38:d.selectResult(-1);break;case 27:d.hideResults();break;case 13:d.insertSelectedResult();break;default:c=
!1}c&&(b.stopPropagation(),b.stopImmediatePropagation(),b.preventDefault())}});b.data("events").keydown.reverse();b.on("keyup",function(b){(b=a.findCurrentAutoCompleteOption())?a.triggerAutoComplete(b):a.hideAutoComplete()})}},findCurrentAutoCompleteOption:function(){var b=this.api,c=b.getFocus();b=b.getOrigin();if(!c||!b||c[0]!=b[0]||c[1]!=b[1])return!1;b=d(c[0]);c=3==c[0].nodeType?b.text().substring(0,c[1]):d(b.contents().get(c[1]-1)).text();b=c.lastIndexOf("@");return-1!=b&&(0==b||c.substr(b-1,
1).match(/(\s|[\](,]|--)/))&&(c=c.substr(b+1),!c.match(/\s/)||10>=c.length)?c=c.replace(new RegExp(String.fromCharCode(160),"g")," "):!1},insertAutoComplete:function(b){this.api.focus();var c=this.api,a=c.getFocus(),e=d(a[0]);3==a[0].nodeType?e=e.text().substring(0,a[1]):(a[0]=e.contents().get(a[1]-1),e=d(a[0]),e=e.text());var g=e.lastIndexOf("@");-1!=g&&(c.setSelection(a[0],g,a[0],e.length),c.insertHtml("@"+XenForo.htmlspecialchars(b)+" "),this.lastAcLookup=b+" ");c.focus()},triggerAutoComplete:function(b){this.lastAcLookup&&
this.lastAcLookup==b||(this.hideAutoComplete(),this.lastAcLookup=b,2<b.length&&"["!=b.substr(0,1)&&(this.acLoadTimer=setTimeout(d.context(this,"autoCompleteLookup"),200)))},autoCompleteLookup:function(){this.acXhr&&this.acXhr.abort();this.acXhr=XenForo.ajax(this.autoCompleteUrl,{q:this.lastAcLookup},d.context(this,"showAutoCompleteResults"),{global:!1,error:!1})},showAutoCompleteResults:function(b){this.acXhr=!1;if(this.lastAcLookup==this.findCurrentAutoCompleteOption()){var c=this.api,a=c.$box.find("iframe"),
e=a.offset(),g=c.getFocus()[0];g=3==g.nodeType?d(g).parent():d(g);var f=g.offset();c={top:e.top+f.top+g.height()-c.$editor.scrollTop(),left:e.left};XenForo.isRTL()&&(c.right=d("html").width()-e.left-a.outerWidth(),c.left="auto");this.acResults.showResults(this.lastAcLookup,b.results,a,c)}},hideAutoComplete:function(){this.acResults.hideResults();this.acLoadTimer&&(clearTimeout(this.acLoadTimer),this.acLoadTimer=!1)},syncEditor:function(){this.$textarea&&this.$textarea.data("redactor")&&this.$textarea.data("redactor").syncCode()},
initAutoSave:function(){var b=this.api,c=this;if(this.$textarea.closest("form").length){this.lastAutoSaveContent=b.getCode();var a=setInterval(function(){c.$textarea.data("redactor")?c.saveDraft():clearInterval(a)},1E3*(this.options.autoSaveFrequency||60))}},saveDraft:function(b,c){var a=this.api,e=this,g=this.$textarea.closest("form"),f=a.$el.prop("disabled")?this.$bbCodeTextArea.val():a.getCode();if(!c&&!b&&f==this.lastAutoSaveContent)return!1;a.syncCode();this.lastAutoSaveContent=f;b=d.Event("BbCodeWysiwygEditorAutoSave");
b.editor=this;b.content=f;b.deleteDraft=c;g.trigger(b);if(b.isDefaultPrevented()||this.autoSaveRunning)return!1;this.autoSaveRunning=!0;XenForo.ajax(this.autoSaveUrl,g.serialize()+(c?"&delete_draft=1":""),function(b){var c=d.Event("BbCodeWysiwygEditorAutoSaveComplete");c.ajaxData=b;g.trigger(c);if(!c.isDefaultPrevented()){c=a.$box.find(".draftNotice");c.length||(c=d('<div class="draftNotice"><span></span></div>'),a.$content.after(c));var f=c.find("span:first"),h;b.draftSaved?h=e.getText("draft_saved"):
b.draftDeleted&&(h=e.getText("draft_deleted"));h&&(f.text(h),c.finish().hide().fadeIn().delay(2E3).fadeOut())}},{global:!1}).complete(function(){e.autoSaveRunning=!1});return!0},triggerAutoSave:function(){this.saveDraft(!0)},triggerAutoSaveDelete:function(){this.saveDraft(!0,!0)},resetAutoSave:function(){if(this.$textarea.data("redactor")){var b=this.api,c=this.$textarea.closest("form");this.lastAutoSaveContent=b.$el.prop("disabled")?this.$bbCodeTextArea.val():b.getCode();c.find(".draftUpdate .draftDeleted, .draftUpdate .draftSaved").finish().fadeOut()}},
insertHtmlCallback:function(b){this.watchImagesElastic(b);var c=this;setTimeout(function(){c.triggerElastic()},300)},wrapSelectionInHtml:function(b,c,a,d){d&&(a='<ins class="selection"></ins>'+a);var e=b.getSelectedHtml();e=e.replace(/^(<p[^>]*>)?/,"$1"+c).replace(/(<\/p>)?$/,a+"$1");b.execCommand("inserthtml",e);b.syncCode();d&&(c=b.$editor.find("ins.selection"),c.length?(b.setSelection(c[0],0,c[0],0),c.remove()):b.focus())},toggleSmilies:function(b){var c=this,a=b.$box.find(".redactor_smilies");
a.length?a.slideToggle():c.smiliesPending||(c.smiliesPending=!0,XenForo.ajax("index.php?editor/smilies",{},function(c){XenForo.hasResponseError(c)||c.templateHtml&&new XenForo.ExtLoader(c,function(){a=d('<div class="redactor_smilies" />').html(c.templateHtml);a.hide();a.on("click",".Smilie",function(a){a.preventDefault();a=d(this);a=d.trim(a.html());b.execCommand("inserthtml",a);b.focus()});b.$box.append(a);a.xfActivate();b.browser("msie")?a.show():a.slideToggle()})}).complete(function(){c.smiliesPending=
!1}))},modalCreateCallback:function(b,c){c.addClass("xenOverlay");var a=d('<form class="formOverlay xenForm" />').append(c.children()).appendTo(c);a.on("submit",function(b){b.preventDefault();a.find(".button.primary").click()});a.on("click","input[type=submit]",function(a){a.stopPropagation();a.preventDefault()});d("#redactor_modal_header").addClass("heading");return c},getLinkModal:function(b){b.saveSelection();var c=b.getSelectedNode(),a;c&&(a=d(c).closest("a",b.$editor[0]));b.modalInit(this.getText("link"),
{url:this.dialogUrl+"&dialog=link"},600,d.proxy(function(){var c=d("#redactor_link_url");d("#redactor_insert_link_btn").click(function(d){d.preventDefault();setTimeout(function(){b.restoreSelection();var d=c.val(),e=b.analyzeSelection();if(""!==d){b.pushUndoStack();var g=d;d.match(/^(mailto|https?):/)||(d.match(/@[a-z0-9-]+\.[a-z0-9\.-]+$/i)?d="mailto:"+d:d.match(/^https?:/i)||(d="http://"+d));a&&a.length?(e=a.attr("href"),a.attr("href",d),a.text()==e&&(a.text(d),b.setSelection(a[0],1,a[0],1))):e.isCollapsed?
(b.pasteHtmlAtCaret('<a href="'+XenForo.htmlspecialchars(d)+'">'+XenForo.htmlspecialchars(g)+'</a><span class="AfterLink">​</span>'),b.$editor.find(".AfterLink").remove()):(b.execCommand("unlink","",!1),b.execCommand("createlink",d,!1))}else a&&a.length&&(b.pushUndoStack(),e.bookmarkSelection(),a.after(a[0].childNodes),a.remove(),e.restoreBookmark());b.syncCode();b.modalClose();b.focus()},150)});a&&a.length&&c.val(a.attr("href").replace(/^mailto:/,""));setTimeout(function(){c.focus()},100)},
b))},getImageModal:function(b){b.saveSelection();var c=b.getSelectedHtml();if(c.match(/^\s*<img[^>]+src="([^"]+)"[^>]*>\s*$/)&&!c.match(/mceSmilie|attachFull|attachThumb/)){var a=RegExp.$1;a=d("<textarea>").html(a).text()}b.modalInit(this.getText("image"),{url:this.dialogUrl+"&dialog=image"},600,d.proxy(function(){var c=d("#redactor_image_link");d("#redactor_image_btn").click(function(a){a.preventDefault();b.restoreSelection();a=c.val();""!==a&&(a.match(/^https?:|ftp:/i)||(a="http://"+a),b.pasteHtmlAtCaret('<img src="'+
XenForo.htmlspecialchars(a)+'" alt="[IMG]" unselectable="on" /> '));b.modalClose();b.observeImages();b.syncCode();b.focus()});a&&c.val(a);setTimeout(function(){c.focus()},100)},b))},getMediaModal:function(b){var c=this;b.saveSelection();b.modalInit(this.getText("media"),{url:this.dialogUrl+"&dialog=media"},600,d.proxy(function(){d("#redactor_insert_media_btn").click(function(a){a.preventDefault();c.insertMedia(a,b)});setTimeout(function(){d("#redactor_media_link").focus()},100)},b))},insertMedia:function(b,
c){XenForo.ajax("index.php?editor/media",{url:d("#redactor_media_link").val()},function(a){XenForo.hasResponseError(a)||(a.matchBbCode?(c.restoreSelection(),c.execCommand("inserthtml",a.matchBbCode),c.syncCode(),c.modalClose()):a.noMatch&&alert(a.noMatch))})},getCodeModal:function(b){var c=this;b.saveSelection();b.modalInit(this.getText("code"),{url:this.dialogUrl+"&dialog=code"},600,d.proxy(function(){d("#redactor_insert_code_btn").click(function(a){a.preventDefault();c.insertCode(a,b)});setTimeout(function(){d("#redactor_code_code").focus()},
100)},b))},insertCode:function(b,c){switch(d("#redactor_code_type").val()){case "html":b="HTML";break;case "php":b="PHP";break;default:b="CODE"}var a=d("#redactor_code_code").val();a=a.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/\t/g," ").replace(/\n /g,"\n ").replace(/ /g," ").replace(/ /g," ").replace(/\n/g,"</p>\n<p>");b="["+b+"]"+a+"[/"+b+"]";b.match(/\n/)&&(b=("<p>"+b+"</p>").replace(/<p><\/p>/g,"<p>"+(d.browser.msie?" ":
"<br>")+"</p>"));c.restoreSelection();c.execCommand("inserthtml",b);c.syncCode();c.modalClose()},getSpoilerModal:function(b){var c=this;b.saveSelection();b.modalInit(this.getText("spoiler"),{url:this.dialogUrl+"&dialog=spoiler"},600,d.proxy(function(){d("#redactor_insert_spoiler_btn").click(function(a){a.preventDefault();c.insertSpoiler(a,b)});setTimeout(function(){d("#redactor_spoiler_title").focus()},100)},b))},insertSpoiler:function(b,c){b=d("#redactor_spoiler_title").val();c.restoreSelection();
b?this.wrapSelectionInHtml(c,'[SPOILER="'+XenForo.htmlspecialchars(b)+'"]',"[/SPOILER]",!0):this.wrapSelectionInHtml(c,"[SPOILER]","[/SPOILER]",!0);c.modalClose()},wysiwygToBbCode:function(b){var c=this;b.getCode().match(/^<p>(<br\s*\/?>|\s| )*<\/p>$/i)?c.wysiwygToBbCodeSuccess(b,{bbCode:""}):XenForo.ajax("index.php?editor/to-bb-code",{html:b.getCode()},function(a){c.wysiwygToBbCodeSuccess(b,a)})},wysiwygToBbCodeSuccess:function(b,c){if(!XenForo.hasResponseError(c)&&"undefined"!=typeof c.bbCode){var a=
b.$box,e=b.$el,g=d('<div class="bbCodeEditorContainer" />'),f=d('<textarea class="textCtrl Elastic" rows="5" />'),h=this;e.prop("disabled")||(f.attr("name",e.attr("name").replace(/_html(]|$)/,"$1")).val(c.bbCode).appendTo(g),this.$textarea.hasClass("NoAttachment")&&f.addClass("NoAttachment"),d("<a />").attr("href","javascript:").text(this.getText("switch_mode_rich")).click(function(){h.bbCodeToWysiwyg(b)}).appendTo(d("<div />").appendTo(g)),e.prop("disabled",!0),b.browser("mozilla")&&d(k).unbind("unload.rte").bind("unload.rte",
function(){e.removeAttr("disabled")}),a.hide(),g.insertAfter(a).xfActivate(),f.focus(),this.$bbCodeTextContainer=g,this.$bbCodeTextArea=f)}},bbCodeToWysiwyg:function(b){var c=this,a=this.$bbCodeTextArea.val();0==d.trim(a).length?this.bbCodeToWysiwygSuccess(b,{html:"<p>"+(d.browser.msie?"":"<br />")+"</p>"}):XenForo.ajax("index.php?editor/to-html",{bbCode:this.$bbCodeTextArea.val()},function(a){c.bbCodeToWysiwygSuccess(b,a)})},bbCodeToWysiwygSuccess:function(b,c){if(!XenForo.hasResponseError(c)&&"undefined"!=
typeof c.html){var a=b.$box,d=b.$el;d.prop("disabled")&&(d.prop("disabled",!1),a.show(),b.setCode(c.html),b.selectFirst(),b.observeFormatting(),this.$bbCodeTextContainer.remove())}},pastePreventCallback:function(b,c,a){var d=a.originalEvent;if(d.clipboardData){var g=d.clipboardData;d=g.items;g=g.types;if(d&&g){for(var f=0;f<g.length;f++)if("text/html"==g[f])return;g=!1;for(f=0;f<d.length;f++)if(d[f].type.match(/^image\/([a-z0-9_-]+)$/i)){var h=d[f].getAsFile(),m=(k.URL||k.webkitURL).createObjectURL(h),
l=this.pasteImageCounter++;this.uploadPastedImage(c,l,RegExp.$1,h)&&(c.insertHtml('<img src="'+m+'" data-paste-id="'+l+'">'),g=!0)}g&&(b.preventDefault(),a.preventDefault(),a.stopPropagation())}}},pasteManipulateCallback:function(b,c){if(c&&c.querySelectorAll&&(c=c.querySelectorAll("img")))for(var a=0;a<c.length;a++)if(c[a].setAttribute("style","-x-ignore: 1"),c[a].src.match(/^data:image\/([a-z0-9_-]+);([a-z0-9_-]+),([\W\w]+)$/i)){var d=this.pasteImageCounter++;c[a].setAttribute("data-paste-id",d);
this.uploadPastedImage(b,d,RegExp.$1,RegExp.$3,RegExp.$2)||c[a].parentNode.removeChild(c[a])}},pasteCleanUpCallback:function(b,c,a){var e=c.browser("msie")&&n.all;a=d.trim(a);var g=a.match(/<[a-zA-Z0-9-]+[^>]* data-redactor="1"/);a=a.replace(/^<div[^>]* data-redactor-wrapper="1"[^>]*>([\w\W]+)<\/div>$/,"$1");c.browser("mozilla")&&(a=a.replace(/<br>$/gi,""));a=a.replace(/<img[^>]+src="webkit-fake-url:[^"]*"[^>]*>/ig,"");a=a.replace(/<style[^>]*>([\w\W]*?)<\/style>/gi,"");a=d.trim(a);a.match(/<p(\s|>)/i)&&
!a.match(/^<(ul|ol|li|p|div|table|tr|th|td|pre|h\d)(\s|>)/)&&(a="<p>"+a.replace(/(<p(\s|>))/,"</p>$1"));a=a.replace(/<\/p>/gi,"</p><p>"+(e?"":"<br>")+"<span><span></span></span></p>");a=a.replace(/<p>(<br>)?<span><span><\/span><\/span><\/p>$/,"");a=a.replace(/<div/gi,"<p").replace(/<\/div>/g,"</p>");a=a.replace(/<p([^>]*)>(\s*|<br\s*\/?>| )<\/p>/gi,"<p$1>"+(e?"":"<br>")+"<span><span></span></span></p>");a=a.replace(/(<[a-zA-Z0-9-]+[^>]*) data-redactor="1"/g,"$1");a=a.replace(/<span[^>]+style="[^"]*white-space:\s*pre[^"]*"[^>]*>([\w\W]+?)<\/span>/g,
function(a,b){return b.replace(/\t/g," ").replace(/ /g," ").replace(/ /g," ")});a=a.replace(/([\w\W]|^)<a\s[^>]*data-user="(\d+, [^"]+)"[^>]*>([\w\W]+?)<\/a>/gi,function(a,b,c,d){c=c.split(", ");return parseInt(c[0],10)?b+("@"==b?"":"@")+c[1].replace(/^@/,""):a});a=a.replace(/(<img\s[^>]*)src="[^"]*"(\s[^>]*)data-url="([^"]+)"/gi,function(a,b,c,d){return b+'src="'+d+'"'+c});a=a.replace(/(( ){2,})( )?/gi,function(a,b,c,d){a=b.length/6;d&&d.length&&a++;d="";for(b=2;b<=a;b+=2)d+=
" ";1==a%2&&(d+=" ");return d});if(!g){var f=function(a,b,c){do{var d=a.replace(b,c);if(d==a)break;a=d}while(1);return d};a=f(a,/<input[^>]*>/gi,"");a=f(a,/<textarea[^>]*>/gi,"");a=f(a,/<select[^>]*>([\w\W]*?)<\/select>/gi,"");a=f(a,/<button[^>]*>([\w\W]*?)<\/button>/gi,"");a=f(a,/<article[^>]*>([\w\W]*?)<\/article>/gi,"$1");a=f(a,/<blockquote[^>]*>([\w\W]*?)<\/blockquote>/gi,"$1");a=f(a,/<del[^>]*>([\w\W]*?)<\/del>/gi,"$1");a=f(a,/<ins[^>]*>([\w\W]*?)<\/ins>/gi,"$1");a=f(a,/<sub[^>]*>([\w\W]*?)<\/sub>/gi,
"$1");a=f(a,/<sup[^>]*>([\w\W]*?)<\/sup>/gi,"$1");a=f(a,/<code[^>]*>([\w\W]*?)<\/code>/gi,"$1");a=f(a,/<tr[^>]*>([\w\W]*?)<\/tr>/gi,"<p>$1</p>");a=f(a,/<td[^>]*>([\w\W]*?)<\/td>/gi,"$1 ");a=f(a,/<th[^>]*>([\w\W]*?)<\/th>/gi,"<b>$1</b> ");a=f(a,/<tbody[^>]*>([\w\W]*?)<\/tbody>/gi,"$1 ");a=f(a,/<table[^>]*>([\w\W]*?)<\/table>/gi,"$1 ");a=a.replace(/<h1[^>]*>([\w\W]+?)<\/h1>/ig,'<p>[paste:font size="6"]<b>$1</b>[/paste:font]</p>');a=a.replace(/<h2[^>]*>([\w\W]+?)<\/h2>/ig,'<p>[paste:font size="5"]<b>$1</b>[/paste:font]</p>');
a=a.replace(/<h3[^>]*>([\w\W]+?)<\/h3>/ig,'<p>[paste:font size="4"]<b>$1</b>[/paste:font]</p>');a=a.replace(/<h4[^>]*>([\w\W]+?)<\/h4>/ig,'<p>[paste:font size="3"]<b>$1</b>[/paste:font]</p>');a=a.replace(/<h5[^>]*>([\w\W]+?)<\/h5>/ig,"<p><b>$1</b></p>");a=a.replace(/<h6[^>]*>([\w\W]+?)<\/h6>/ig,"<p><b>$1</b></p>");a=a.replace(/<pre[^>]*>([\w\W]+?)<\/pre>/ig,function(a,b){a="";b.length?(a="<p>"+b.replace(/\r?\n/g,"</p><p>")+"</p>",a=a.replace(/\t/g," ").replace(/<p> /g,"<p> ").replace(/ /g,
" ").replace(/ /g," ").replace(/<span[^>]*>( |<br>)<\/span>/gi,"$1"),a=a.replace(/(( ){2,})( )?/gi,function(a,b,c,d){a=b.length/6;d&&d.length&&a++;d="";for(b=2;b<=a;b+=2)d+=" ";1==a%2&&(d+=" ");return d})):a="<p></p>";return a.replace(/<p([^>]*)>(\s*|<br\s*\/?>| )<\/p>/gi,"<p$1>"+(e?"":"<br>")+"<span><span></span></span></p>")})}c.$editor.data("xenForoElastic")&&setTimeout(function(){c.$editor.data("xenForoElastic")()},0);!a.match(/<(?!br\s*\/?)([a-z0-9-]+)(\s|\/|>)/i)&&
a.match(/<br\s*\/?>/i)&&(a="<p>"+a.replace(/<br\s*\/?>\s*/ig,"</p><p>")+"</p>",a=a.replace(/<p><\/p>/ig,"<p>"+(e?"":"<br>")+"<span><span></span></span></p>"));g&&(a=a.replace(/<span><span><\/span><\/span>/gi,""),b.preventDefault());return a},uploadPastedImage:function(b,c,a,e,g){var f=b.$box.closest("form").find(".AttachmentUploader");if(!f.length||this.$textarea.hasClass("NoAttachment"))return!1;try{var h=new FormData;if("string"==typeof e){var k="base64"==g?atob(e):unescape(e);b=[];for(g=0;g<k.length;g++)b.push(k.charCodeAt(g));
e=new Blob([new Uint8Array(b)],{type:"image/"+a})}var l=new Date,n="upload_"+l.getFullYear()+"-"+(l.getMonth()+1)+"-"+l.getDate()+"_"+l.getHours()+"-"+l.getMinutes()+"-"+l.getSeconds()+"."+a;h.append("upload",e,n);h.append("filename",n);h.append("_xfToken",XenForo._csrfToken);h.append("_xfNoRedirect","1");f.find(".HiddenInput").each(function(){var a=d(this);h.append(a.data("name"),a.data("value"))})}catch(r){return!1}var p=this;d.ajax({url:XenForo.canonicalizeUrl(f.data("action"),XenForo.ajaxBaseHref),
method:"POST",dataType:"json",data:h,processData:!1,contentType:!1}).done(function(a){if(p.$textarea.data("redactor")){var b=p.$textarea.getEditor().find("img[data-paste-id="+c+"]");XenForo.hasResponseError(a)?b.remove():(b.data("paste-id","").attr("src",a.viewUrl).attr("alt","attachFull"+a.attachment_id).addClass("attachFull"),f.trigger({type:"AttachmentUploaded",ajaxData:a}))}}).fail(function(a){p.$textarea.getEditor().find("img[data-paste-id="+c+"]").remove();try{var b=d.parseJSON(a.responseText);
b&&XenForo.hasResponseError(b)}catch(t){}});return!0},getText:function(b,c){var a=RELANG.xf||RLANG;return"string"==typeof a[b]?a[b]:c||b}};XenForo.BbCodeWysiwygEditor_EXTEND=XenForo.BbCodeWysiwygEditor_EXTEND||{};XenForo.register("textarea.BbCodeWysiwygEditor","XenForo.BbCodeWysiwygEditor")}(jQuery,this,document);