Make WordPress Core

Ticket #21785: 21785-media-manager.2.diff

File 21785-media-manager.2.diff, 8.2 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 1e8c3fd..e89975f 100644
     
    602602        margin: 0;
    603603}
    604604
     605.media-frame-title .suggested-dimensions {
     606        font-size: 14px;
     607        float: right;
     608        margin-right: 20px;
     609}
     610
     611.media-frame-content .crop-content {
     612        display: block;
     613        margin: auto;
     614        max-width: 100%;
     615        max-height: 100%;
     616}
     617
    605618/**
    606619 * Iframes
    607620 */
  • src/wp-includes/js/media-views.js

    diff --git src/wp-includes/js/media-views.js src/wp-includes/js/media-views.js
    index db5ea30..c3e8bd1 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 ) {
     
    12421245        });
    12431246
    12441247        /**
     1248         * wp.media.controller.Cropper
     1249         *
     1250         * Allows for a cropping step.
     1251         *
     1252         * @constructor
     1253         * @augments wp.media.controller.State
     1254         * @augments Backbone.Model
     1255         */
     1256        media.controller.Cropper = media.controller.State.extend({
     1257                defaults: {
     1258                        id: 'cropper',
     1259                        title: l10n.cropImage,
     1260                        toolbar: 'crop',
     1261                        content: 'crop',
     1262                        router: false,
     1263                        canSkipCrop: false
     1264                },
     1265
     1266                activate: function() {
     1267                        this.frame.on( 'content:create:crop', this.createCropContent, this );
     1268                        this.frame.on( 'close', this.removeCropper, this );
     1269                        this.set('selection', new Backbone.Collection(this.frame._selection.single));
     1270                },
     1271
     1272                deactivate: function() {
     1273                        this.frame.toolbar.mode('browse');
     1274                },
     1275
     1276                createCropContent: function() {
     1277                        this.cropperView = new wp.media.view.Cropper({controller: this,
     1278                                        attachment: this.get('selection').first() });
     1279                        this.cropperView.on('image-loaded', this.createCropToolbar, this);
     1280                        this.frame.content.set(this.cropperView);
     1281
     1282                },
     1283                removeCropper: function() {
     1284                        this.imgSelect.cancelSelection();
     1285                        this.imgSelect.setOptions({remove: true});
     1286                        this.imgSelect.update();
     1287                        this.cropperView.remove();
     1288                },
     1289                createCropToolbar: function() {
     1290                        var canSkipCrop, toolbarOptions;
     1291
     1292                        canSkipCrop = this.get('canSkipCrop') || false;
     1293
     1294                        toolbarOptions = {
     1295                                controller: this.frame,
     1296                                items: {
     1297                                        insert: {
     1298                                                style:    'primary',
     1299                                                text:     l10n.cropImage,
     1300                                                priority: 80,
     1301                                                requires: { library: false, selection: false },
     1302
     1303                                                click: function() {
     1304                                                        var self = this,
     1305                                                                selection = this.controller.state().get('selection').first();
     1306
     1307                                                        selection.set({cropDetails: this.controller.state().imgSelect.getSelection()});
     1308
     1309                                                        this.$el.text(l10n.cropping);
     1310                                                        this.$el.attr('disabled', true);
     1311                                                        this.controller.state().doCrop(selection, function(croppedImage) {
     1312                                                                var img = JSON.parse(croppedImage);
     1313
     1314                                                                self.controller.trigger('cropped', img);
     1315                                                                self.controller.close();
     1316                                                        });
     1317                                                }
     1318                                        }
     1319                                }
     1320                        };
     1321
     1322                        if ( canSkipCrop ) {
     1323                                _.extend( toolbarOptions.items, {
     1324                                        skip: {
     1325                                                style:          'primary',
     1326                                                text:   l10n.skipCropping,
     1327                                                priority:       70,
     1328                                                requires:       { library: false, selection: false },
     1329                                                click:          function() {
     1330                                                        var selection = this.controller.state().get('selection').first();
     1331                                                        this.controller.state().cropperView.remove();
     1332                                                        this.controller.trigger('skippedcrop', selection);
     1333                                                        this.controller.close();
     1334                                                }
     1335                                        }
     1336                                });
     1337                        }
     1338
     1339                        this.frame.toolbar.set( new wp.media.view.Toolbar(toolbarOptions) );
     1340                },
     1341
     1342                doCrop: function(attachment, callback) {
     1343                        $.post(wp.ajax.settings.url, {
     1344                                dataType: 'json',
     1345                                action: 'header_crop',
     1346                                data: attachment.toJSON()
     1347                        }, callback);
     1348                }
     1349        });
     1350
     1351        /**
    12451352         * ========================================================================
    12461353         * VIEWS
    12471354         * ========================================================================
     
    55765683                        this.$( '.embed-image-settings' ).scrollTop( 0 );
    55775684                }
    55785685        });
    5579 }(jQuery));
     5686
     5687        /**
     5688         * wp.media.view.Cropper
     5689         *
     5690         * Uses the imgAreaSelect plugin to allow a user to crop an image.
     5691         *
     5692         * Takes imgAreaSelect options from
     5693         * wp.customize.HeaderControl.calculateImageSelectOptions via
     5694         * wp.customize.HeaderControl.openMM.
     5695         *
     5696         * @constructor
     5697         * @augments wp.media.View
     5698         * @augments wp.Backbone.View
     5699         * @augments Backbone.View
     5700         */
     5701        media.view.Cropper = media.View.extend({
     5702                tagName: 'img',
     5703                className: 'crop-content',
     5704                initialize: function() {
     5705                        _.bindAll(this, 'onImageLoad');
     5706                        this.$el.attr('src', this.options.attachment.get('url'));
     5707                },
     5708                ready: function() {
     5709                        this.$el.on('load', this.onImageLoad);
     5710                        $(window).on('resize', _.debounce(this.onImageLoad, 250));
     5711                },
     5712                remove: function() {
     5713                        this.$el.remove();
     5714                        this.$el.off();
     5715                        wp.media.View.prototype.remove.apply(this, arguments);
     5716                },
     5717                prepare: function() {
     5718                        return {
     5719                                title: l10n.cropYourImage,
     5720                                url: this.options.attachment.get('url')
     5721                        };
     5722                },
     5723                onImageLoad: function() {
     5724                        var imgOptions = this.controller.frame.options.imgSelectOptions;
     5725                        if (typeof imgOptions === 'function') {
     5726                                imgOptions = imgOptions(this.options.attachment, this.controller);
     5727                        }
     5728                        this.trigger('image-loaded');
     5729                        this.controller.imgSelect = this.$el.imgAreaSelect(imgOptions);
     5730                }
     5731
     5732        });
     5733
     5734}(jQuery, wp));
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index ebcfa0e..ed5b06a 100644
    function wp_prepare_attachment_for_js( $attachment ) { 
    21352135                'nonces'      => array(
    21362136                        'update' => false,
    21372137                        'delete' => false,
     2138                        'crop' => false,
    21382139                ),
    21392140                'editLink'   => false,
    21402141        );
    function wp_prepare_attachment_for_js( $attachment ) { 
    21472148        if ( current_user_can( 'delete_post', $attachment->ID ) )
    21482149                $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID );
    21492150
     2151        if ( current_user_can( 'edit_post', $attachment->ID ) )
     2152                $response['nonces']['crop'] = wp_create_nonce( 'crop-image_' . $attachment->ID );
     2153
    21502154        if ( $meta && 'image' === $type ) {
    21512155                $sizes = array();
    21522156                /** This filter is documented in wp-admin/includes/media.php */
    function wp_enqueue_media( $args = array() ) { 
    23392343                // Edit Image
    23402344                'imageDetailsTitle'     => __( 'Image Details' ),
    23412345                'imageReplaceTitle'     => __( 'Replace Image' ),
    2342                 'imageDetailsCancel'    => __( 'Cancel Edit' ),
     2346                'imageDetailsCancel'     => __( 'Cancel Edit' ),
     2347
     2348                // Crop Image
     2349                /* translators: title for Media Manager library view */
     2350                'chooseImage' => __( 'Choose Image' ),
     2351                /* translators: button to select an image from the MM library to crop */
     2352                'selectAndCrop' => __( 'Select and Crop' ),
     2353                /* translators: button to choose not to crop the selected image */
     2354                'skipCropping' => __( 'Skip Cropping' ),
     2355                /* translators: button to choose to crop the selected image */
     2356                'cropImage' => __( 'Crop Image' ),
     2357                'cropYourImage' => __( 'Crop your image' ),
     2358                /* translators: button label changes to this while the image is being cropped server-side */
     2359                'cropping' => __( 'Cropping...' ),
     2360                /* translators: suggested width of header image in pixels */
     2361                'suggestedWidth' => __( 'Suggested width is %d pixels.' ),
     2362                /* translators: suggested height of header image in pixels */
     2363                'suggestedHeight' => __( 'Suggested height is %d pixels.' ),
    23432364
    23442365                // Playlist
    23452366                'playlistDragInfo'    => __( 'Drag and drop to reorder tracks.' ),
    function theme_supports_thumbnails( $post ) { 
    25902611        }
    25912612
    25922613        return current_theme_supports( 'post-thumbnails', $post->post_type );
    2593 }
    2594  No newline at end of file
     2614}