/*
* XenForo attachment_editor.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(a,m,h){a instanceof String&&(a=String(a));for(var k=a.length,l=0;l<k;l++){var n=a[l];if(m.call(h,n,l,a))return{i:l,v:n}}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(a,m,h){a!=Array.prototype&&a!=Object.prototype&&(a[m]=h.value)};
$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(a,m,h,k){if(m){h=$jscomp.global;a=a.split(".");for(k=0;k<a.length-1;k++){var l=a[k];l in h||(h[l]={});h=h[l]}a=a[a.length-1];k=h[a];m=m(k);m!=k&&null!=m&&$jscomp.defineProperty(h,a,{configurable:!0,writable:!0,value:m})}};
$jscomp.polyfill("Array.prototype.find",function(a){return a?a:function(a,h){return $jscomp.findInternal(this,a,h).v}},"es6","es3");
!function(a,m,h,k){var l=XenForo.speed.normal,n=XenForo.speed.fast,p=!1;XenForo.AttachmentUploader=function(c){p||(p=!0,a.browser.mozilla&&"function"==typeof SWFUpload&&a(function(){var b=XenForo.isRTL()?"9999em":"-9999em",e=a('<object width="100" height="100" type="application/x-shockwave-flash" style="visibility: hidden; position: absolute; top: 0; left: '+b+'" />').appendTo("body");setTimeout(function(){e.remove()},250)}));var f=a(c.data("trigger"));c.closest("form");var b=a(c.data("placeholder")),
e={},d=null,g=null,r=c.data("maxfilesize");c.data("maxuploads");var l=c.data("extensions"),k=c.data("uniquekey");l=l.replace(/[;*.]/g,"").replace(/,{2,}/g,",").replace(/^,+/,"").replace(/,+$/,"");c.show();var n=XenForo.canonicalizeUrl(c.data("flashurl")||"js/swfupload/Flash/swfupload.swf");console.info("flash url: %s",n);"function"!=typeof SWFUpload||m.navigator.userAgent.match(/Android|iOS|iPhone|iPad|Mobile Safari/i)||(d=new SWFUpload({upload_url:c.data("action"),file_post_name:c.data("postname"),
file_types:"*."+l.toLowerCase().replace(/,/g,";*."),post_params:a.extend({_xfToken:XenForo._csrfToken,_xfNoRedirect:1,_xfResponseType:"json"},e),button_placeholder_id:b.attr("id"),button_width:1,button_height:1,button_window_mode:SWFUpload.WINDOW_MODE.TRANSPARENT,button_cursor:SWFUpload.CURSOR.HAND,flash_url:n,prevent_swf_caching:!1,swfupload_loaded_handler:function(){this.setButtonDimensions(f.outerWidth(),f.outerHeight());a(this.movieElement).css("top",f.position().top);c.find(".HiddenInput").each(function(b,
e){d.addPostParam(a(e).data("name"),a(e).data("value"))});a(h).bind("CSRFRefresh",function(a){a.ajaxData&&(d.addPostParam("_xfToken",a.ajaxData.csrfToken),d.addPostParam("_xfSessionId",a.ajaxData.sessionId))})},file_dialog_complete_handler:function(a,b){try{0<this.getStats().files_queued&&this.startUpload(this.getFile(0).ID)}catch(t){this.debug(t)}},file_queued_handler:function(b){switch(b.name.substr(b.name.lastIndexOf(".")).toLowerCase()){case ".jpg":case ".jpeg":case ".jpe":case ".png":case ".gif":var e=
!0;break;default:e=!1}var d=a.Event("AttachmentQueueValidation");d.file=b;d.swfUpload=this;d.isImage=e;c.trigger(d);d.isDefaultPrevented()||(b.size>r&&!e?(this.cancelUpload(b.id,!1),"function"==typeof this.settings.file_queue_error_handler&&this.settings.file_queue_error_handler.call(this,b,SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT,"The uploaded file is too large.")):(d=a.Event("AttachmentQueued"),d.file=b,d.swfUpload=this,d.isImage=e,c.trigger(d)))},file_queue_error_handler:function(b,e,d){var f=
a.Event("AttachmentQueueError");f.file=b;f.errorCode=e;f.message=d;f.swfUpload=this;c.trigger(f);f.isDefaultPrevented()||g(b,e,d)},upload_start_handler:function(a){console.log("Uploading %s",a.name)},upload_progress_handler:function(a,b){c.trigger({type:"AttachmentUploadProgress",file:a,bytes:b,swfUpload:this})},upload_success_handler:function(b,e,d){try{var g=a.parseJSON(e)}catch(u){console.warn(u);return}g.error?c.trigger({type:"AttachmentUploadError",file:b,ajaxData:g,swfUpload:this}):c.trigger({type:"AttachmentUploaded",
file:b,ajaxData:g,swfUpload:this})},upload_error_handler:function(b,a,e){a!=SWFUpload.UPLOAD_ERROR.FILE_CANCELLED&&(console.warn("Upload failed: %o",arguments),c.trigger({type:"AttachmentUploadError",file:b,errorCode:a,message:e,ajaxData:{error:[c.data("err-unknown")]},swfUpload:this}))},upload_complete_handler:function(a){try{0<this.getStats().files_queued?this.startUpload(this.getFile(0).ID):console.info("All files uploaded.")}catch(q){this.debug(q)}}}),g=function(a,b,e){b=c.data("err"+b)||e;a?
XenForo.alert(b+"<br /><br />"+XenForo.htmlspecialchars(a.name)):XenForo.alert(b)});a(h).bind("AutoInlineUploadComplete",function(b){if(k&&b.ajaxData&&k!==b.ajaxData.key)return!1;if(a(b.target).is("form.AttachmentUploadForm"))return f.overlay()&&f.overlay().close(),c.trigger({type:"AttachmentUploaded",ajaxData:b.ajaxData}),!1});return{getSwfUploader:function(){return d},swfAlert:g}};XenForo.AttachmentEditor=function(c){this.setVisibility=function(b){var a=c.closest(".ctrlUnit"),d=c.find(".AttachmentInsertAllBlock"),
g=c.find(".AttachedFile:not(#AttachedFileTemplate)"),f=g.filter(".AttachedImage");console.log("Attachments changed, total files: %d, images: %d",g.length,f.length);0==a.length&&(a=c);!0===b?g.length?(1<f.length?d.show():d.hide(),a.show()):a.hide():g.length?(1<f.length?a.is(":hidden")?d.show():d.xfFadeDown(XenForo.speed.fast):a.is(":hidden")?d.hide():d.xfFadeUp(XenForo.speed.fast,!1,XenForo.speed.fast,"swing"),a.xfFadeDown(XenForo.speed.normal)):(d.slideUp(XenForo.speed.fast),a.xfFadeUp(XenForo.speed.normal,
!1,!1,"swing"))};this.setVisibility(!0);a("#AttachmentUploader").bind({click:function(){a("textarea.BbCodeWysiwygEditor").each(function(){var b=a(this).data("XenForo.BbCodeWysiwygEditor");b&&b.blurEditor()})},AttachmentQueued:function(b){var e=b.file,d=e.uniqueIdentifier||e.id;console.info("Queued file %s (%d bytes).",e.name,e.size);var g=a("#AttachedFileTemplate").clone().attr("id",d);g.find(".Filename").text(e.name);g.find(".ProgressCounter").text("0%");g.find(".ProgressGraphic span").css("width",
"0%");b.isImage&&g.addClass("AttachedImage");g.xfInsert("appendTo",".AttachmentList.New",null,l);g.find(".AttachmentCanceller").css("display","block").click(function(){b.swfUpload?b.swfUpload.cancelUpload(b.file.id):e.flowObj&&e.cancel();g.xfRemove(null,function(){c.trigger("AttachmentsChanged")},n,"swing")});c.trigger("AttachmentsChanged")},AttachmentUploadProgress:function(b){var e=b.file;b=b.bytes;var d=e.uniqueIdentifier||e.id;console.log("Uploaded %d/%d bytes.",b,e.size);e=Math.min(100,Math.ceil(100*
b/e.size));b=e+"%";d=a("#"+d);var c=d.find(".ProgressCounter"),f=d.find(".ProgressGraphic");c.text(b);f.css("width",b);100<=e&&d.find(".AttachmentCanceller").prop("disabled",!0).addClass("disabled");f.width()>c.outerWidth()&&c.appendTo(f)},AttachmentUploadError:function(b){var e="",d=b.file,c=d.uniqueIdentifier||d.id;a.each(b.ajaxData.error,function(a,b){e+=b+"\n"});XenForo.alert(e+"<br /><br />"+XenForo.htmlspecialchars(d.name));d=a("#"+c);var f=d.closest(".AttachmentEditor");d.xfRemove(null,function(){f.trigger("AttachmentsChanged")},
n,"swing");console.warn("AttachmentUploadError: %o",b)},AttachmentUploaded:function(b){if(b.file){var e=b.file,d=a("#"+(e.uniqueIdentifier||e.id)),f=d.find(".AttachmentText"),h=a(b.ajaxData.templateHtml),k;f.fadeOut(XenForo.speed.fast,function(){h.find(".AttachmentText").xfInsert("insertBefore",f,"fadeIn",XenForo.speed.fast);k=d.find(".Thumbnail");k.html(h.find(".Thumbnail").html());f.xfRemove();d.attr("id","attachment"+b.ajaxData.attachment_id)})}else d=a("#attachment"+b.ajaxData.attachment_id),
d.length||(d=a(b.ajaxData.templateHtml).xfInsert("appendTo",c.find(".AttachmentList.New"),null,l));c.trigger("AttachmentsChanged")}});var f=a.context(this,"setVisibility");a("#QuickReply").bind("QuickReplyComplete",function(a){c.find(".AttachmentList.New li:not(#AttachedFileTemplate)").xfRemove().promise().always(f)});c.bind("AttachmentsChanged",f)};XenForo.AttachmentInserter=function(a){a.click(function(c){var b=a.closest(".AttachedFile").find(".Thumbnail a"),e=b.data("attachmentid");var d=b.find("img").attr("src");
b=b.attr("href");c.preventDefault();"thumb"==a.attr("name")?(c="[ATTACH]"+e+"[/ATTACH] ",d='<img src="'+d+'" class="attachThumb bbCodeImage" alt="attachThumb'+e+'" /> '):(c="[ATTACH=full]"+e+"[/ATTACH] ",d='<img src="'+b+'" class="attachFull bbCodeImage" alt="attachFull'+e+'" /> ');if(e=XenForo.getEditorInForm(a.closest("form"),":not(.NoAttachment)"))if(e.$editor){e.insertHtml(d);var f=e.$editor.data("xenForoElastic");f&&(setTimeout(function(){f()},250),setTimeout(function(){f()},1E3))}else e.val(e.val()+
c)})};XenForo.AttachmentDeleter=function(c){c.css("display","block").click(function(c){var b=a(c.target),e=b.attr("href")||b.data("href"),d=b.closest(".AttachedFile");c=b.closest(".AttachedFile").find(".Thumbnail a").data("attachmentid");if(e)return d.xfFadeUp(XenForo.speed.normal,null,n,"swing"),XenForo.ajax(e,"",function(a,b){if(XenForo.hasResponseError(a))return d.xfFadeDown(XenForo.speed.normal),!1;var c=d.closest(".AttachmentEditor");d.xfRemove(null,function(){c.trigger("AttachmentsChanged")},
n,"swing")}),c&&(b=XenForo.getEditorInForm(b.closest("form"),":not(.NoAttachment)"))&&b.$editor&&(b.$editor.find("img[alt=attachFull"+c+"], img[alt=attachThumb"+c+"]").remove(),(c=b.$editor.data("xenForoElastic"))&&c()),!1;console.warn("Unable to locate href for attachment deletion from %o",b)})};XenForo.AttachmentInsertAll=function(c){c.click(function(){a(".AttachmentInserter[name="+c.attr("name")+"]").each(function(c,b){a(b).trigger("click")})})};XenForo.AttachmentDeleteAll=function(c){c.click(function(){a(".AttachmentDeleter").each(function(c,
b){a(b).trigger("click")})})};XenForo.register(".AttachmentUploader","XenForo.AttachmentUploader");XenForo.register(".AttachmentEditor","XenForo.AttachmentEditor");XenForo.register(".AttachmentInserter","XenForo.AttachmentInserter");XenForo.register(".AttachmentDeleter","XenForo.AttachmentDeleter");XenForo.register(".AttachmentInsertAll","XenForo.AttachmentInsertAll");XenForo.register(".AttachmentDeleteAll","XenForo.AttachmentDeleteAll")}(jQuery,this,document);