When uploading files through the Plupload bridge, attempt to detect images on upload. see #21390.
git-svn-id: https://develop.svn.wordpress.org/trunk@22041 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c6b63ec34d
commit
424f5b21e6
@ -142,11 +142,29 @@ if ( typeof wp === 'undefined' )
|
||||
|
||||
this.uploader.bind( 'FilesAdded', function( up, files ) {
|
||||
_.each( files, function( file ) {
|
||||
file.attachment = wp.media.model.Attachment.create( _.extend({
|
||||
var attributes, image;
|
||||
|
||||
// Generate attributes for a new `Attachment` model.
|
||||
attributes = _.extend({
|
||||
file: file,
|
||||
uploading: true,
|
||||
date: new Date()
|
||||
}, _.pick( file, 'loaded', 'size', 'percent' ) ) );
|
||||
}, _.pick( file, 'loaded', 'size', 'percent' ) );
|
||||
|
||||
// Handle early mime type scanning for images.
|
||||
image = /(?:jpe?g|png|gif)$/i.exec( file.name );
|
||||
|
||||
// Did we find an image?
|
||||
if ( image ) {
|
||||
attributes.type = 'image';
|
||||
|
||||
// `jpeg`, `png` and `gif` are valid subtypes.
|
||||
// `jpg` is not, so map it to `jpeg`.
|
||||
attributes.subtype = ( 'jpg' === image[0] ) ? 'jpeg' : image[0];
|
||||
}
|
||||
|
||||
// Create the `Attachment`.
|
||||
file.attachment = wp.media.model.Attachment.create( attributes );
|
||||
|
||||
Uploader.queue.add( file.attachment );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user