Make WordPress Core

Changeset 22041


Ignore:
Timestamp:
09/27/2012 05:52:42 AM (14 years ago)
Author:
koopersmith
Message:

When uploading files through the Plupload bridge, attempt to detect images on upload. see #21390.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/plupload/wp-plupload.js

    r21814 r22041  
    143143                this.uploader.bind( 'FilesAdded', function( up, files ) {
    144144                        _.each( files, function( file ) {
    145                                 file.attachment = wp.media.model.Attachment.create( _.extend({
     145                                var attributes, image;
     146
     147                                // Generate attributes for a new `Attachment` model.
     148                                attributes = _.extend({
    146149                                        file:      file,
    147150                                        uploading: true,
    148151                                        date:      new Date()
    149                                 }, _.pick( file, 'loaded', 'size', 'percent' ) ) );
     152                                }, _.pick( file, 'loaded', 'size', 'percent' ) );
     153
     154                                // Handle early mime type scanning for images.
     155                                image = /(?:jpe?g|png|gif)$/i.exec( file.name );
     156
     157                                // Did we find an image?
     158                                if ( image ) {
     159                                        attributes.type = 'image';
     160
     161                                        // `jpeg`, `png` and `gif` are valid subtypes.
     162                                        // `jpg` is not, so map it to `jpeg`.
     163                                        attributes.subtype = ( 'jpg' === image[0] ) ? 'jpeg' : image[0];
     164                                }
     165
     166                                // Create the `Attachment`.
     167                                file.attachment = wp.media.model.Attachment.create( attributes );
    150168
    151169                                Uploader.queue.add( file.attachment );
Note: See TracChangeset for help on using the changeset viewer.