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

1 line
5.5 KiB
JavaScript
Raw Normal View History

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