2019-10-03 23:02:00 +02:00
|
|
|
window.wp=window.wp||{},function(a,b){var c;"undefined"!=typeof _wpPluploadSettings&&(c=function(a){var d,e,f,g,h=this,i={container:"container",browser:"browse_button",dropzone:"drop_element"},j={};if(this.supports={upload:c.browser.supported},this.supported=this.supports.upload,this.supported){this.plupload=b.extend(!0,{multipart_params:{}},c.defaults),this.container=document.body,b.extend(!0,this,a);for(e in this)b.isFunction(this[e])&&(this[e]=b.proxy(this[e],this));for(e in i)this[e]&&(this[e]=b(this[e]).first(),this[e].length?(this[e].prop("id")||this[e].prop("id","__wp-uploader-id-"+c.uuid++),this.plupload[i[e]]=this[e].prop("id")):delete this[e]);(this.browser&&this.browser.length||this.dropzone&&this.dropzone.length)&&(this.uploader=new plupload.Uploader(this.plupload),delete this.plupload,this.param(this.params||{}),delete this.params,d=function(a,c,e){var i,k;return c&&c.responseHeaders?(k=c.responseHeaders.match(/x-wp-upload-attachment-id:\s*(\d+)/i),k&&k[1]?(k=k[1],i=j[e.id],i&&i>4?(b.ajax({type:"post",url:ajaxurl,dataType:"json",data:{action:"media-create-image-subsizes",_wpnonce:_wpPluploadSettings.defaults.multipart_params._wpnonce,attachment_id:k,_wp_upload_failed_cleanup:!0}}),void f(a,c,e,"no-retry")):(i?j[e.id]=++i:j[e.id]=1,void b.ajax({type:"post",url:ajaxurl,dataType:"json",data:{action:"media-create-image-subsizes",_wpnonce:_wpPluploadSettings.defaults.multipart_params._wpnonce,attachment_id:k}}).done(function(b){b.success?g(h.uploader,e,b):(b.data&&b.data.message&&(a=b.data.message),f(a,c,e,"no-retry"))}).fail(function(b){return 500===b.status?void d(a,c,e):void f(a,c,e,"no-retry")}))):void f(pluploadL10n.http_error_image,c,e,"no-retry")):void f(pluploadL10n.http_error_image,c,e,"no-retry")},f=function(a,b,e,f){var g=e.type&&0===e.type.indexOf("image/"),i=b&&b.status;return"no-retry"!==f&&500===i&&g?void d(a,b,e):(e.attachment&&e.attachment.destroy(),c.errors.unshift({message:a||pluploadL10n.default_error,data:b,file:e}),void h.error(a,b,e))},g=function(a,b,d){var e;_.each(["file","loaded","size","percent"],function(a){b.attachment.unset(a)}),b.attachment.set(_.extend(d.data,{uploading:!1})),wp.media.model.Attachment.get(d.data.id,b.attachment),e=c.queue.all(function(a){return!a.get("uploading")}),e&&c.queue.reset(),h.success(b.attachment)},this.uploader.bind("init",function(a){var d,e,f,g=h.dropzone;if(f=h.supports.dragdrop=a.features.dragdrop&&!c.browser.mobile,g){if(g.toggleClass("supports-drag-drop",!!f),!f)return g.unbind(".wp-uploader");g.bind("dragover.wp-uploader",function(){d&&clearTimeout(d),e||(g.trigger("dropzone:enter").addClass("drag-over"),e=!0)}),g.bind("dragleave.wp-uploader, drop.wp-uploader",function(){d=setTimeout(function(){e=!1,g.trigger("dropzone:leave").removeClass("drag-over")},0)}),h.ready=!0,b(h).trigger("uploader:ready")}}),this.uploader.bind("postinit",function(a){a.refresh(),h.init()}),this.uploader.init(),this.browser?this.browser.on("mouseenter",this.refresh):(this.uploader.disableBrowse(!0),b("#"+this.uploader.id+"_html5_container").hide()),this.uploader.bind("FilesAdded",function(a,b){_.each(b,function(a){var b,d;plupload.FAILED!==a.status&&(b=_.extend({file:a,uploading:!0,date:new Date,filename:a.name,menuOrder:0,uploadedTo:wp.media.model.settings.post.id},_.pick(a,"loaded","size","percent")),d=/(?:jpe?g|png|gif)$/i.exec(a.name),d&&(b.type="image",b.subtype="jpg"===d[0]?"jpeg":d[0]),a.attachment=wp.media.model.Attachment.create(b),c.queue.add(a.attachment),h.added(a.attachment))}),a.refresh(),a.start()}),this.uploader.bind("UploadProgress",function(a,b){b.attachment.set(_.pick(b,"loaded","percent")),h.progress(b.attachment)}),this.uploader.bind("FileUploaded",function(a,b,c){try{c=JSON.parse(c.response)}catch(d){return f(pluploadL10n.default_error,d,b)}return!_.isObject(c)||_.isUndefined(c.success)?f(pluploadL10n.default_error,null,b):c.success?void g(a,b,c):f(c.data&&c.data.message,c.data,b)}),this.uploader.bind("Error",function(a,b){var d,e=pluploadL10n.default_error;for(d in c.errorMap)if(b.code===plupload[d]){e=c.errorMap[d],_.isFunction(e)&&(e=e(b.file,b));
|