Ticket #21785: 21785-media-manager.2.diff
File 21785-media-manager.2.diff, 8.2 KB (added by , 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
602 602 margin: 0; 603 603 } 604 604 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 605 618 /** 606 619 * Iframes 607 620 */ -
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
1 1 /* global _wpMediaViewsL10n, confirm, getUserSetting, setUserSetting */ 2 (function($ ){2 (function($, wp){ 3 3 var media = wp.media, l10n; 4 4 5 5 // Link any localized strings. … … 390 390 * @access private 391 391 */ 392 392 _renderTitle: function( view ) { 393 view.$el.text( this.get('title') || '' ); 393 var title = this.get('title'); 394 view.$el.html( title.html || title || '' ); 394 395 }, 395 396 /** 396 397 * @access private … … 455 456 priority = this.get('priority'); 456 457 457 458 if ( ! menuItem && title ) { 458 menuItem = { text: title }; 459 if ( title.text !== undefined ) { 460 menuItem = { text: title.text }; 461 } else { 462 menuItem = { text: title }; 463 } 459 464 460 if ( priority ) {465 if ( priority ) 461 466 menuItem.priority = priority; 462 }463 467 } 464 468 465 if ( ! menuItem ) {469 if ( ! menuItem ) 466 470 return; 467 }468 471 469 472 view.set( this.id, menuItem ); 470 }473 } 471 474 }); 472 475 473 476 _.each(['toolbar','content'], function( region ) { … … 1242 1245 }); 1243 1246 1244 1247 /** 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 /** 1245 1352 * ======================================================================== 1246 1353 * VIEWS 1247 1354 * ======================================================================== … … 5576 5683 this.$( '.embed-image-settings' ).scrollTop( 0 ); 5577 5684 } 5578 5685 }); 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 ) { 2135 2135 'nonces' => array( 2136 2136 'update' => false, 2137 2137 'delete' => false, 2138 'crop' => false, 2138 2139 ), 2139 2140 'editLink' => false, 2140 2141 ); … … function wp_prepare_attachment_for_js( $attachment ) { 2147 2148 if ( current_user_can( 'delete_post', $attachment->ID ) ) 2148 2149 $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID ); 2149 2150 2151 if ( current_user_can( 'edit_post', $attachment->ID ) ) 2152 $response['nonces']['crop'] = wp_create_nonce( 'crop-image_' . $attachment->ID ); 2153 2150 2154 if ( $meta && 'image' === $type ) { 2151 2155 $sizes = array(); 2152 2156 /** This filter is documented in wp-admin/includes/media.php */ … … function wp_enqueue_media( $args = array() ) { 2339 2343 // Edit Image 2340 2344 'imageDetailsTitle' => __( 'Image Details' ), 2341 2345 '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.' ), 2343 2364 2344 2365 // Playlist 2345 2366 'playlistDragInfo' => __( 'Drag and drop to reorder tracks.' ), … … function theme_supports_thumbnails( $post ) { 2590 2611 } 2591 2612 2592 2613 return current_theme_supports( 'post-thumbnails', $post->post_type ); 2593 } 2594 No newline at end of file 2614 }