Make WordPress Core

Ticket #21785: 21785.suggested-dimensions.6.diff

File 21785.suggested-dimensions.6.diff, 4.9 KB (added by gcorne, 11 years ago)
  • src/wp-admin/js/customize-controls.js

    diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
    index 88e020c..8cc4130 100644
     
    419419                 * @param {event} event
    420420                 */
    421421                openMedia: function(event) {
    422                         var suggestedWidth, suggestedHeight,
    423                                 l10n = _wpMediaViewsL10n;
     422                        var l10n = _wpMediaViewsL10n;
    424423
    425424                        event.preventDefault();
    426425
    427                         suggestedWidth = l10n.suggestedWidth.replace('%d', _wpCustomizeHeader.data.width);
    428                         suggestedHeight = l10n.suggestedHeight.replace('%d', _wpCustomizeHeader.data.height);
    429 
    430                         /* '<span class="suggested-dimensions">' + suggestedWidth + ' ' + suggestedHeight + '</span>' */
    431 
    432426                        this.frame = wp.media({
    433                                 title: l10n.chooseImage,
    434                                 library: {
    435                                         type: 'image'
    436                                 },
    437427                                button: {
    438428                                        text: l10n.selectAndCrop,
    439429                                        close: false
    440430                                },
    441                                 multiple: false,
    442                                 imgSelectOptions: this.calculateImageSelectOptions
     431                                states: [
     432                                        new wp.media.controller.Library({
     433                                                title:     l10n.chooseImage,
     434                                                library:   wp.media.query({ type: 'image' }),
     435                                                multiple:  false,
     436                                                priority:  20,
     437                                                suggestedWidth: _wpCustomizeHeader.data.width,
     438                                                suggestedHeight: _wpCustomizeHeader.data.height
     439                                        }),
     440                                        new wp.media.controller.Cropper({
     441                                                imgSelectOptions: this.calculateImageSelectOptions
     442                                        })
     443                                ]
    443444                        });
    444445
    445                         this.frame.states.add([new wp.media.controller.Cropper()]);
    446 
    447446                        this.frame.on('select', this.onSelect, this);
    448447                        this.frame.on('cropped', this.onCropped, this);
    449448                        this.frame.on('skippedcrop', this.onSkippedCrop, this);
  • src/wp-includes/css/media-views.css

    diff --git src/wp-includes/css/media-views.css src/wp-includes/css/media-views.css
    index 2e172b1..c339723 100644
     
    929929        line-height: 18px;
    930930        font-size: 13px;
    931931        color: #666;
     932        margin-right: 0.5em;
    932933}
    933934
    934935/**
  • src/wp-includes/js/media-views.js

    diff --git src/wp-includes/js/media-views.js src/wp-includes/js/media-views.js
    index 97dd232..2838ffe 100644
     
    18431843                                display:    state.get('displaySettings'),
    18441844                                dragInfo:   state.get('dragInfo'),
    18451845
     1846                                suggestedWidth:  state.get('suggestedWidth'),
     1847                                suggestedHeight: state.get('suggestedHeight'),
     1848
    18461849                                AttachmentView: state.get('AttachmentView')
    18471850                        });
    18481851                },
     
    33123315                                }) );
    33133316                        }
    33143317                },
     3318
     3319                prepare: function() {
     3320                        var suggestedWidth = this.controller.state().get('suggestedWidth'),
     3321                                suggestedHeight = this.controller.state().get('suggestedHeight');
     3322
     3323                        if ( suggestedWidth && suggestedHeight ) {
     3324                                return {
     3325                                        suggestedWidth: suggestedWidth,
     3326                                        suggestedHeight: suggestedHeight
     3327                                };
     3328                        }
     3329                },
    33153330                /**
    33163331                 * @returns {wp.media.view.UploaderInline} Returns itself to allow chaining
    33173332                 */
     
    51965211                                        priority: -40
    51975212                                }) );
    51985213                        }
     5214
     5215                        if ( this.options.suggestedWidth && this.options.suggestedHeight ) {
     5216                                this.toolbar.set( 'suggestedDimensions', new media.View({
     5217                                        el: $( '<div class="instructions">' + l10n.suggestedDimensions + ' ' + this.options.suggestedWidth + ' &times; ' + this.options.suggestedHeight + '</div>' )[0],
     5218                                        priority: -40
     5219                                }) );
     5220                        }
    51995221                },
    52005222
    52015223                updateContent: function() {
     
    62286250                        };
    62296251                },
    62306252                onImageLoad: function() {
    6231                         var imgOptions = this.controller.frame.options.imgSelectOptions;
     6253                        var imgOptions = this.controller.get('imgSelectOptions');
    62326254                        if (typeof imgOptions === 'function') {
    62336255                                imgOptions = imgOptions(this.options.attachment, this.controller);
    62346256                        }
  • src/wp-includes/media-template.php

    diff --git src/wp-includes/media-template.php src/wp-includes/media-template.php
    index f38638d..3d2f368 100644
    function wp_print_media_templates() { 
    205205                                        printf( __( 'Maximum upload file size: %d%s.' ), esc_html($upload_size_unit), esc_html($byte_sizes[$u]) );
    206206                                ?></p>
    207207
     208                                <# if ( data.suggestedWidth && data.suggestedHeight ) { #>
     209                                        <p class="suggested-dimensions">
     210                                                <?php _e( 'Suggested image dimensions:' ); ?> {{{data.suggestedWidth}}} &times; {{{data.suggestedHeight}}}
     211                                        </p>
     212                                <# } #>
     213
    208214                                <?php
    209215                                /** This action is documented in wp-admin/includes/media.php */
    210216                                do_action( 'post-upload-ui' ); ?>
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index adeaed4..f8c5d7e 100644
    function wp_enqueue_media( $args = array() ) { 
    25272527                'cropImage' => __( 'Crop Image' ),
    25282528                'cropYourImage' => __( 'Crop your image' ),
    25292529                'cropping' => __( 'Cropping&hellip;' ),
    2530                 'suggestedWidth' => __( 'Suggested width is %d pixels.' ),
    2531                 'suggestedHeight' => __( 'Suggested height is %d pixels.' ),
     2530                'suggestedDimensions' => __( 'Suggested image dimensions:' ),
    25322531                'cropError' => __( 'There has been an error cropping your image.' ),
    25332532
    25342533                // Edit Audio