Make WordPress Core

Ticket #21785: 21785-media-manager.diff

File 21785-media-manager.diff, 8.3 KB (added by ehg, 11 years ago)
  • src/wp-includes/css/media-views.css

    diff --git src/wp-includes/css/media-views.css src/wp-includes/css/media-views.css
    index 107a131..5d21acf 100644
     
    603603        margin: 0;
    604604}
    605605
     606.media-frame-title .suggested-dimensions {
     607        font-size: 14px;
     608        float: right;
     609        margin-right: 20px;
     610}
     611
     612.media-frame-content #crop-content {
     613        width: 100%;
     614        height: 100%;
     615}
     616
    606617/**
    607618 * Iframes
    608619 */
  • src/wp-includes/js/media-views.js

    diff --git src/wp-includes/js/media-views.js src/wp-includes/js/media-views.js
    index 1904a0f..dc6148c 100644
     
    11/* global _wpMediaViewsL10n, confirm, getUserSetting, setUserSetting */
    2 (function($){
     2(function($, wp){
    33        var media = wp.media, l10n;
    44
    55        // Link any localized strings.
     
    390390                 * @access private
    391391                 */
    392392                _renderTitle: function( view ) {
    393                         view.$el.text( this.get('title') || '' );
     393                        var title = this.get('title');
     394                        view.$el.html( title.html || title || '' );
    394395                },
    395396                /**
    396397                 * @access private
     
    455456                                priority = this.get('priority');
    456457
    457458                        if ( ! menuItem && title ) {
    458                                 menuItem = { text: title };
     459                                if ( title.text !== undefined ) {
     460                                        menuItem = { text: title.text };
     461                                } else {
     462                                        menuItem = { text: title };
     463                                }
    459464
    460                                 if ( priority ) {
     465                                if ( priority )
    461466                                        menuItem.priority = priority;
    462                                 }
    463467                        }
    464468
    465                         if ( ! menuItem ) {
     469                        if ( ! menuItem )
    466470                                return;
    467                         }
    468471
    469472                        view.set( this.id, menuItem );
    470                 }
     473                        }
    471474        });
    472475
    473476        _.each(['toolbar','content'], function( region ) {
     
    11991202        });
    12001203
    12011204        /**
     1205         * wp.media.controller.Cropper
     1206         *
     1207         * Allows for a cropping step.
     1208         *
     1209         * @constructor
     1210         * @augments wp.media.controller.State
     1211         * @augments Backbone.Model
     1212         */
     1213        media.controller.Cropper = media.controller.State.extend({
     1214                defaults: {
     1215                        id: 'cropper',
     1216                        title: l10n.cropImage,
     1217                        toolbar: 'crop',
     1218                        content: 'crop',
     1219                        router: false,
     1220                        canSkipCrop: false
     1221                },
     1222
     1223                activate: function() {
     1224                        this.frame.on( 'content:create:crop', this.createCropContent, this );
     1225                        this.frame.on( 'close', this.removeCropper, this );
     1226                        this.set('selection', new Backbone.Collection(this.frame._selection.single));
     1227                },
     1228
     1229                deactivate: function() {
     1230                        this.frame.toolbar.mode('browse');
     1231                },
     1232
     1233                createCropContent: function() {
     1234                        this.cropperView = new wp.media.view.Cropper({controller: this,
     1235                                        attachment: this.get('selection').first() });
     1236                        this.cropperView.on('image-loaded', this.createCropToolbar, this);
     1237                        this.frame.content.set(this.cropperView);
     1238
     1239                },
     1240                removeCropper: function() {
     1241                        this.imgSelect.cancelSelection();
     1242                        this.imgSelect.setOptions({remove: true});
     1243                        this.imgSelect.update();
     1244                        this.cropperView.remove();
     1245                },
     1246                createCropToolbar: function() {
     1247                        var canSkipCrop, toolbarOptions;
     1248
     1249                        canSkipCrop = this.get('canSkipCrop') || false;
     1250
     1251                        toolbarOptions = {
     1252                                controller: this.frame,
     1253                                items: {
     1254                                        insert: {
     1255                                                style:    'primary',
     1256                                                text:     l10n.cropImage,
     1257                                                priority: 80,
     1258                                                requires: { library: false, selection: false },
     1259
     1260                                                click: function() {
     1261                                                        var self = this,
     1262                                                                selection = this.controller.state().get('selection').first();
     1263
     1264                                                        selection.set({cropDetails: this.controller.state().imgSelect.getSelection()});
     1265
     1266                                                        this.$el.text(l10n.cropping);
     1267                                                        this.$el.attr('disabled', true);
     1268                                                        this.controller.state().doCrop(selection, function(croppedImage) {
     1269                                                                var img = JSON.parse(croppedImage);
     1270
     1271                                                                self.controller.trigger('cropped', img);
     1272                                                                self.controller.close();
     1273                                                        });
     1274                                                }
     1275                                        }
     1276                                }
     1277                        };
     1278
     1279                        if ( canSkipCrop ) {
     1280                                _.extend( toolbarOptions.items, {
     1281                                        skip: {
     1282                                                style:          'primary',
     1283                                                text:   l10n.skipCropping,
     1284                                                priority:       70,
     1285                                                requires:       { library: false, selection: false },
     1286                                                click:          function() {
     1287                                                        var selection = this.controller.state().get('selection').first();
     1288                                                        this.controller.state().cropperView.remove();
     1289                                                        this.controller.trigger('skippedcrop', selection);
     1290                                                        this.controller.close();
     1291                                                }
     1292                                        }
     1293                                });
     1294                        }
     1295
     1296                        this.frame.toolbar.set( new wp.media.view.Toolbar(toolbarOptions) );
     1297                },
     1298
     1299                doCrop: function(attachment, callback) {
     1300                        $.post(wp.ajax.settings.url, {
     1301                                dataType: 'json',
     1302                                action: 'header_crop',
     1303                                data: attachment.toJSON()
     1304                        }, callback);
     1305                }
     1306        });
     1307
     1308        /**
    12021309         * ========================================================================
    12031310         * VIEWS
    12041311         * ========================================================================
     
    52525359                        this.$( '.embed-image-settings' ).scrollTop( 0 );
    52535360                }
    52545361        });
    5255 }(jQuery));
     5362
     5363        /**
     5364         * wp.media.view.Cropper
     5365         *
     5366         * Uses the imgAreaSelect plugin to allow a user to crop an image.
     5367         *
     5368         * Takes imgAreaSelect options from
     5369         * wp.customize.HeaderControl.calculateImageSelectOptions via
     5370         * wp.customize.HeaderControl.openMM.
     5371         *
     5372         * @constructor
     5373         * @augments wp.media.View
     5374         * @augments wp.Backbone.View
     5375         * @augments Backbone.View
     5376         */
     5377        media.view.Cropper = media.View.extend({
     5378                id: 'crop-content',
     5379                template: _.template('<img id="image-to-crop" src="<%= url %>" style="max-height: 100%; max-width: 100%; display: block; margin: auto;">'),
     5380                initialize: function() {
     5381                        _.bindAll( this, 'onImageLoad' );
     5382                },
     5383                ready: function() {
     5384                        this.$el.find('img').on('load', this.onImageLoad);
     5385                        $(window).on('resize', _.debounce(this.onImageLoad, 250));
     5386                },
     5387                remove: function() {
     5388                        var img = this.$el.find('img');
     5389                        img.remove();
     5390                        img.off();
     5391                        wp.media.View.prototype.remove.apply(this, arguments);
     5392                },
     5393                prepare: function() {
     5394                        return {
     5395                                title: l10n.cropYourImage,
     5396                                url: this.options.attachment.get('url')
     5397                        };
     5398                },
     5399                onImageLoad: function() {
     5400                        var imgOptions = this.controller.frame.options.imgSelectOptions;
     5401                        if ( typeof imgOptions === 'function' ) {
     5402                                imgOptions = imgOptions(this.options.attachment, this.controller);
     5403                        }
     5404                        this.trigger('image-loaded');
     5405                        this.controller.imgSelect = this.$el.find('img').imgAreaSelect(imgOptions);
     5406                }
     5407
     5408        });
     5409
     5410}(jQuery, wp));
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 129bc92..047518f 100644
    function wp_prepare_attachment_for_js( $attachment ) { 
    18691869                'nonces'      => array(
    18701870                        'update' => false,
    18711871                        'delete' => false,
     1872                        'crop' => false,
    18721873                ),
    18731874                'editLink'   => false,
    18741875        );
    function wp_prepare_attachment_for_js( $attachment ) { 
    18811882        if ( current_user_can( 'delete_post', $attachment->ID ) )
    18821883                $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID );
    18831884
     1885        if ( current_user_can( 'edit_post', $attachment->ID ) )
     1886                $response['nonces']['crop'] = wp_create_nonce( 'crop-image_' . $attachment->ID );
     1887
    18841888        if ( $meta && 'image' === $type ) {
    18851889                $sizes = array();
    18861890                /** This filter is documented in wp-admin/includes/media.php */
    function wp_enqueue_media( $args = array() ) { 
    20712075                // Edit Image
    20722076                'imageDetailsTitle'     => __( 'Image Details' ),
    20732077                'imageReplaceTitle'     => __( 'Replace Image' ),
    2074                 'imageDetailsCancel'     => __( 'Cancel Edit' )
     2078                'imageDetailsCancel'     => __( 'Cancel Edit' ),
     2079
     2080                // Crop Image
     2081                /* translators: title for Media Manager library view */
     2082                'chooseImage' => __( 'Choose Image' ),
     2083                /* translators: button to select an image from the MM library to crop */
     2084                'selectAndCrop' => __( 'Select and Crop' ),
     2085                /* translators: button to choose not to crop the selected image */
     2086                'skipCropping' => __( 'Skip Cropping' ),
     2087                /* translators: button to choose to crop the selected image */
     2088                'cropImage' => __( 'Crop Image' ),
     2089                'cropYourImage' => __( 'Crop your image' ),
     2090                /* translators: button label changes to this while the image is being cropped server-side */
     2091                'cropping' => __( 'Cropping...' ),
     2092                /* translators: suggested width of header image in pixels */
     2093                'suggestedWidth' => __( 'Suggested width is %d pixels.' ),
     2094                /* translators: suggested height of header image in pixels */
     2095                'suggestedHeight' => __( 'Suggested height is %d pixels.' ),
    20752096        );
    20762097
    20772098        $settings = apply_filters( 'media_view_settings', $settings, $post );
    function theme_supports_thumbnails( $post ) { 
    23022323        }
    23032324
    23042325        return current_theme_supports( 'post-thumbnails', $post->post_type );
    2305 }
    2306  No newline at end of file
     2326}