WordPress/wp-includes/js/plupload/wp-plupload.min.js

1 line
5.6 KiB
JavaScript

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;return e&&e.id?(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,_wp_temp_upload_ref:e.id,_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,_wp_temp_upload_ref:e.id}}).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.upload_failed,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("BeforeUpload",function(a,b){b.type&&0===b.type.indexOf("image/")?a.settings.multipart_params._wp_temp_upload_ref=b.id:a.settings.multipart_params._wp_temp_upload_ref=""}),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));break}f(e,b,b.file),a.refresh()}))}},b.extend(c,_wpPluploadSettings),c.uuid=0,c.errorMap={FAILED:pluploadL10n.upload_failed,FILE_EXTENSION_ERROR:pluploadL10n.invalid_filetype,IMAGE_FORMAT_ERROR:pluploadL10n.not_an_image,IMAGE_MEMORY_ERROR:pluploadL10n.image_memory_exceeded,IMAGE_DIMENSIONS_ERROR:pluploadL10n.image_dimensions_exceeded,GENERIC_ERROR:pluploadL10n.upload_failed,IO_ERROR:pluploadL10n.io_error,SECURITY_ERROR:pluploadL10n.security_error,FILE_SIZE_ERROR:function(a){return pluploadL10n.file_exceeds_size_limit.replace("%s",a.name)},HTTP_ERROR:function(a){return a.type&&0===a.type.indexOf("image/")?pluploadL10n.http_error_image:pluploadL10n.http_error}},b.extend(c.prototype,{param:function(a,c){return 1===arguments.length&&"string"==typeof a?this.uploader.settings.multipart_params[a]:void(arguments.length>1?this.uploader.settings.multipart_params[a]=c:b.extend(this.uploader.settings.multipart_params,a))},init:function(){},error:function(){},success:function(){},added:function(){},progress:function(){},complete:function(){},refresh:function(){var a,c,d,e;if(this.browser){for(a=this.browser[0];a;){if(a===document.body){c=!0;break}a=a.parentNode}c||(e="wp-uploader-browser-"+this.uploader.id,d=b("#"+e),d.length||(d=b('<div class="wp-uploader-browser" />').css({position:"fixed",top:"-1000px",left:"-1000px",height:0,width:0}).attr("id","wp-uploader-browser-"+this.uploader.id).appendTo("body")),d.append(this.browser))}this.uploader.refresh()}}),c.queue=new wp.media.model.Attachments([],{query:!1}),c.errors=new Backbone.Collection,a.Uploader=c)}(wp,jQuery);