View file upload/js/xenforo/attachment_editor_new.js

File size: 9.41Kb
/*
 * XenForo attachment_editor_new.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(b,n,k){b instanceof String&&(b=String(b));for(var l=b.length,h=0;h<l;h++){var q=b[h];if(n.call(k,q,h,b))return{i:h,v:q}}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(b,n,k){b!=Array.prototype&&b!=Object.prototype&&(b[n]=k.value)};
$jscomp.getGlobal=function(b){return"undefined"!=typeof window&&window===b?b:"undefined"!=typeof global&&null!=global?global:b};$jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(b,n,k,l){if(n){k=$jscomp.global;b=b.split(".");for(l=0;l<b.length-1;l++){var h=b[l];h in k||(k[h]={});k=k[h]}b=b[b.length-1];l=k[b];n=n(l);n!=l&&null!=n&&$jscomp.defineProperty(k,b,{configurable:!0,writable:!0,value:n})}};
$jscomp.polyfill("Array.prototype.find",function(b){return b?b:function(b,k){return $jscomp.findInternal(this,b,k).v}},"es6","es3");
!function(b,n,k,l){var h=XenForo.speed.normal,q=XenForo.speed.fast;XenForo.AttachmentUploader=function(c){var d=b(c.data("trigger"));c.closest("form");var a={},f=function(b,a,f){(a=c.data("err-"+a)||f)||(a=c.data("err-unknown"));b?XenForo.alert(a+"<br /><br />"+XenForo.htmlspecialchars(b.name)):XenForo.alert(a)},g=c.data("maxfilesize");c.data("maxuploads");var e=c.data("extensions"),r=c.data("uniquekey");e=e.replace(/[;*.]/g,"").replace(/,{2,}/g,",").replace(/^,+/,"").replace(/,+$/,"");c.show();var p=
n.Flow?!0:!1,h=navigator.userAgent;h.match(/Android [1-4]/)&&(h=h.match(/Chrome\/([0-9]+)/),!h||33>parseInt(h[1],10))&&(console.log("Old Android WebView detected. Must fallback to basic uploader."),p=!1);if(p){var l=!1;p={target:c.data("action"),allowDuplicateUploads:!0,fileParameterName:c.data("postname"),query:function(){var f=b.extend({_xfToken:XenForo._csrfToken,_xfNoRedirect:1,_xfResponseType:l?"json-text":"json"},a);c.find(".HiddenInput").each(function(a,c){a=b(c);f[a.data("name")]=a.data("value")});
return f},simultaneousUploads:1,testChunks:!1,chunkSize:4294967296,readFileFn:function(a,b,f,c,g){var e="slice";a.file.slice?e="slice":a.file.mozSlice?e="mozSlice":a.file.webkitSlice&&(e="webkitSlice");c||(c="");g.readFinished(a.file[e](b,f,c))}};var m=new Flow(p);m.support||(m=new FustyFlow(p),l=!0);p=b("<span />").insertAfter(d).append(d);m.assignBrowse(p[0],!1,!1,{accept:"."+e.toLowerCase().replace(/,/g,",.")});l?(e=d.outerWidth(),30<e&&p.css("width",e)):(e=p.find("input[type=file]"),e.css("overflow",
"hidden"),e.css(XenForo.isRTL()?"right":"left",-1E3));d.on("click BeforeOverlayTrigger",function(a){a.preventDefault()});m.on("fileAdded",function(a){var e=!1;a.id=a.uniqueIdentifier;switch(a.name.substr(a.name.lastIndexOf(".")).toLowerCase()){case ".jpg":case ".jpeg":case ".jpe":case ".png":case ".gif":e=!0}var d=b.Event("AttachmentQueueValidation");d.file=a;d.flow=m;d.isImage=e;c.trigger(d);if(d.isDefaultPrevented())return!1;if(a.size>g&&!e)return f(a,110),!1;d=b.Event("AttachmentQueued");d.file=
a;d.flow=m;d.isImage=e;c.trigger(d)});m.on("filesSubmitted",function(){m.upload()});m.on("fileProgress",function(a){a.id=a.uniqueIdentifier;c.trigger({type:"AttachmentUploadProgress",file:a,bytes:Math.round(a.progress()*a.size),flow:m})});m.on("fileSuccess",function(a,f){try{l&&"<"==f.substr(0,1)&&(f=b(b.parseHTML(f)).text());var e=b.parseJSON(f)}catch(t){console.warn(t);return}a.id=a.uniqueIdentifier;e.error?c.trigger({type:"AttachmentUploadError",file:a,ajaxData:e,flow:m}):c.trigger({type:"AttachmentUploaded",
file:a,ajaxData:e,flow:m})});m.on("fileError",function(a,b){a.id=a.uniqueIdentifier;c.trigger({type:"AttachmentUploadError",file:a,errorCode:0,message:b,ajaxData:{error:[c.data("err-unknown")]},flow:m})})}else console.error("flow.js must be loaded");b(k).bind("AutoInlineUploadComplete",function(a){if(r&&a.ajaxData&&r!==a.ajaxData.key)return!1;if(b(a.target).is("form.AttachmentUploadForm"))return d.overlay()&&d.overlay().close(),c.trigger({type:"AttachmentUploaded",ajaxData:a.ajaxData}),!1});return{getSwfUploader:function(){return null},
getFlowUploader:function(){return m},swfAlert:f,attachmentErrorAlert:f}};XenForo.AttachmentEditor=function(c){this.setVisibility=function(a){var b=c.closest(".ctrlUnit"),g=c.find(".AttachmentInsertAllBlock"),e=c.find(".AttachedFile:not(#AttachedFileTemplate)"),d=e.filter(".AttachedImage");console.log("Attachments changed, total files: %d, images: %d",e.length,d.length);0==b.length&&(b=c);!0===a?e.length?(1<d.length?g.show():g.hide(),b.show()):b.hide():e.length?(1<d.length?b.is(":hidden")?g.show():
g.xfFadeDown(XenForo.speed.fast):b.is(":hidden")?g.hide():g.xfFadeUp(XenForo.speed.fast,!1,XenForo.speed.fast,"swing"),b.xfFadeDown(XenForo.speed.normal)):(g.slideUp(XenForo.speed.fast),b.xfFadeUp(XenForo.speed.normal,!1,!1,"swing"))};this.setVisibility(!0);b("#AttachmentUploader").bind({click:function(){b("textarea.BbCodeWysiwygEditor").each(function(){var a=b(this).data("XenForo.BbCodeWysiwygEditor");a&&a.blurEditor()})},AttachmentQueued:function(a){var f=a.file,g=f.uniqueIdentifier||f.id;console.info("Queued file %s (%d bytes).",
f.name,f.size);var e=b("#AttachedFileTemplate").clone().attr("id",g);e.find(".Filename").text(f.name);e.find(".ProgressCounter").text("0%");e.find(".ProgressGraphic span").css("width","0%");a.isImage&&e.addClass("AttachedImage");e.xfInsert("appendTo",".AttachmentList.New",null,h);e.find(".AttachmentCanceller").css("display","block").click(function(){a.swfUpload?a.swfUpload.cancelUpload(a.file.id):f.flowObj&&f.cancel();e.xfRemove(null,function(){c.trigger("AttachmentsChanged")},q,"swing")});c.trigger("AttachmentsChanged")},
AttachmentUploadProgress:function(a){var f=a.file;a=a.bytes;var c=f.uniqueIdentifier||f.id;console.log("Uploaded %d/%d bytes.",a,f.size);f=Math.min(100,Math.ceil(100*a/f.size));a=f+"%";c=b("#"+c);var e=c.find(".ProgressCounter"),d=c.find(".ProgressGraphic");e.text(a);d.css("width",a);100<=f&&c.find(".AttachmentCanceller").prop("disabled",!0).addClass("disabled");d.width()>e.outerWidth()&&e.appendTo(d)},AttachmentUploadError:function(a){var c="",d=a.file,e=d.uniqueIdentifier||d.id;b.each(a.ajaxData.error,
function(a,b){c+=b+"\n"});XenForo.alert(c+"<br /><br />"+XenForo.htmlspecialchars(d.name));d=b("#"+e);var h=d.closest(".AttachmentEditor");d.xfRemove(null,function(){h.trigger("AttachmentsChanged")},q,"swing");console.warn("AttachmentUploadError: %o",a)},AttachmentUploaded:function(a){if(a.file){var d=a.file,g=b("#"+(d.uniqueIdentifier||d.id)),e=g.find(".AttachmentText"),k=b(a.ajaxData.templateHtml),l;e.fadeOut(XenForo.speed.fast,function(){k.find(".AttachmentText").xfInsert("insertBefore",e,"fadeIn",
XenForo.speed.fast);l=g.find(".Thumbnail");l.html(k.find(".Thumbnail").html());e.xfRemove();g.attr("id","attachment"+a.ajaxData.attachment_id)})}else g=b("#attachment"+a.ajaxData.attachment_id),g.length||(g=b(a.ajaxData.templateHtml).xfInsert("appendTo",c.find(".AttachmentList.New"),null,h));c.trigger("AttachmentsChanged")}});var d=b.context(this,"setVisibility");b("#QuickReply").bind("QuickReplyComplete",function(a){c.find(".AttachmentList.New li:not(#AttachedFileTemplate)").xfRemove().promise().always(d)});
c.bind("AttachmentsChanged",d)};XenForo.AttachmentInserter=function(b){b.click(function(c){var a=b.closest(".AttachedFile").find(".Thumbnail a"),d=a.data("attachmentid");var g=a.find("img").attr("src");a=a.attr("href");c.preventDefault();"thumb"==b.attr("name")?(c="[ATTACH]"+d+"[/ATTACH] ",g='<img src="'+g+'" class="attachThumb bbCodeImage" alt="attachThumb'+d+'" /> '):(c="[ATTACH=full]"+d+"[/ATTACH] ",g='<img src="'+a+'" class="attachFull bbCodeImage" alt="attachFull'+d+'" /> ');if(d=XenForo.getEditorInForm(b.closest("form"),
":not(.NoAttachment)"))if(d.$editor){d.insertHtml(g);var e=d.$editor.data("xenForoElastic");e&&(setTimeout(function(){e()},250),setTimeout(function(){e()},1E3))}else d.val(d.val()+c)})};XenForo.AttachmentDeleter=function(c){c.css("display","block").click(function(d){var a=b(d.target),c=a.attr("href")||a.data("href"),g=a.closest(".AttachedFile");d=a.closest(".AttachedFile").find(".Thumbnail a").data("attachmentid");if(c)return g.xfFadeUp(XenForo.speed.normal,null,q,"swing"),XenForo.ajax(c,"",function(a,
b){if(XenForo.hasResponseError(a))return g.xfFadeDown(XenForo.speed.normal),!1;var c=g.closest(".AttachmentEditor");g.xfRemove(null,function(){c.trigger("AttachmentsChanged")},q,"swing")}),d&&(a=XenForo.getEditorInForm(a.closest("form"),":not(.NoAttachment)"))&&a.$editor&&(a.$editor.find("img[alt=attachFull"+d+"], img[alt=attachThumb"+d+"]").remove(),(d=a.$editor.data("xenForoElastic"))&&d()),!1;console.warn("Unable to locate href for attachment deletion from %o",a)})};XenForo.AttachmentInsertAll=
function(c){c.click(function(){b(".AttachmentInserter[name="+c.attr("name")+"]").each(function(c,a){b(a).trigger("click")})})};XenForo.AttachmentDeleteAll=function(c){c.click(function(){b(".AttachmentDeleter").each(function(c,a){b(a).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);