Make WordPress Core

Ticket #28750: 28750.patch

File 28750.patch, 2.7 KB (added by iseulde, 11 years ago)
  • src/wp-includes/js/media-views.js

     
    45684568                        this.model.on( 'change:title', this._syncTitle, this );
    45694569                        this.model.on( 'change:caption', this._syncCaption, this );
    45704570                        this.model.on( 'change:percent', this.progress, this );
     4571                        this.model.on( 'change:preview', this.preview, this );
    45714572
    45724573                        // Update the selection.
    45734574                        this.model.on( 'add', this.select, this );
     
    46624663                                this.$bar.width( this.model.get('percent') + '%' );
    46634664                        }
    46644665                },
     4666
     4667                preview: function() {
     4668                        console.log( this.$el );
     4669                },
     4670
    46654671                /**
    46664672                 * @param {Object} event
    46674673                 */
  • src/wp-includes/js/plupload/wp-plupload.js

     
    174174
    175175                this.uploader.bind( 'FilesAdded', function( up, files ) {
    176176                        _.each( files, function( file ) {
    177                                 var attributes, image;
     177                                var attributes, image, reader;
     178
     179                                if ( window.FileReader ) {
     180                                        reader = new FileReader();
     181                                }
    178182
    179183                                // Ignore failed uploads.
    180184                                if ( plupload.FAILED === file.status ) {
     
    201205                                        // `jpeg`, `png` and `gif` are valid subtypes.
    202206                                        // `jpg` is not, so map it to `jpeg`.
    203207                                        attributes.subtype = ( 'jpg' === image[0] ) ? 'jpeg' : image[0];
     208
     209                                        if ( reader ) {
     210                                                reader.onload = function ( event ) {
     211                                                        $( reader ).trigger( 'preview', event.target.result );
     212                                                };
     213       
     214                                                reader.readAsDataURL( file.getNative() );
     215                                        }
    204216                                }
    205217
    206218                                // Create the `Attachment`.
    207219                                file.attachment = wp.media.model.Attachment.create( attributes );
    208220
     221                                reader && $( reader ).on( 'preview', function( event, preview ) {
     222                                        file.attachment.set( { preview: preview } );
     223                                });
     224
    209225                                Uploader.queue.add( file.attachment );
    210226
    211227                                self.added( file.attachment );
  • src/wp-includes/media-template.php

     
    393393                <# } #>
    394394                <div class="attachment-preview type-{{ data.type }} subtype-{{ data.subtype }} {{ data.orientation }}">
    395395                        <# if ( data.uploading ) { #>
     396                                <# if ( data.preview ) { #>
     397                                        <div class="thumbnail">
     398                                                <div class="centered">
     399                                                        <img src="{{ data.preview }}" draggable="false" alt="" style="opacity: 0.5" />
     400                                                </div>
     401                                        </div>
     402                                <# } #>
    396403                                <div class="media-progress-bar"><div></div></div>
    397404                        <# } else if ( 'image' === data.type ) { #>
    398405                                <div class="thumbnail">