Ticket #21811: 21811-modal-05-refresh.patch
File 21811-modal-05-refresh.patch, 11.3 KB (added by , 11 years ago) |
---|
-
src/wp-admin/js/image-edit.js
diff --git src/wp-admin/js/image-edit.js src/wp-admin/js/image-edit.js index 9eaf51b..fd8fc7a 100644
var imageEdit = window.imageEdit = { 5 5 iasapi : {}, 6 6 hold : {}, 7 7 postid : '', 8 _view : {}, 8 9 9 10 intval : function(f) { 10 11 return f | 0; … … var imageEdit = window.imageEdit = { 287 288 }); 288 289 }, 289 290 290 open : function(postid, nonce) { 291 open : function( postid, nonce, view ) { 292 this._view = view; 293 291 294 var data, elem = $('#image-editor-' + postid), head = $('#media-head-' + postid), 292 295 btn = $('#imgedit-open-btn-' + postid), spin = btn.siblings('.spinner'); 293 296 … … var imageEdit = window.imageEdit = { 319 322 }, 320 323 321 324 initCrop : function(postid, image, parent) { 322 var t = this, selW = $('#imgedit-sel-width-' + postid), 323 selH = $('#imgedit-sel-height-' + postid); 325 var t = this, 326 selW = $('#imgedit-sel-width-' + postid), 327 selH = $('#imgedit-sel-height-' + postid), 328 $img; 324 329 325 330 t.iasapi = $(image).imgAreaSelect({ 326 331 parent: parent, … … var imageEdit = window.imageEdit = { 330 335 minWidth: 3, 331 336 minHeight: 3, 332 337 333 onInit: function() { 338 onInit: function( img ) { 339 // Ensure that the imgareaselect wrapper elements are position:absolute 340 // (even if we're in a position:fixed modal) 341 $img = $( img ); 342 $img.next().css( 'position', 'absolute' ) 343 .nextAll( '.imgareaselect-outer' ).css( 'position', 'absolute' ); 344 334 345 parent.children().mousedown(function(e){ 335 346 var ratio = false, sel, defRatio; 336 347 … … var imageEdit = window.imageEdit = { 397 408 398 409 this.iasapi = {}; 399 410 this.hold = {}; 400 $('#image-editor-' + postid).fadeOut('fast', function() { 401 $('#media-head-' + postid).fadeIn('fast'); 402 $(this).empty(); 403 }); 411 412 // If we've loaded the editor in the context of a Media Modal, then switch to the previous view, 413 // whatever that might have been. 414 if ( this._view && 'object' === typeof this._view ){ 415 this._view.cancel(); 416 } 417 418 // In case we are not accessing the image editor in the context of a View, close the editor the old-skool way 419 else { 420 $('#image-editor-' + postid).fadeOut('fast', function() { 421 $('#media-head-' + postid).fadeIn('fast'); 422 $(this).empty(); 423 }); 424 } 425 426 404 427 }, 405 428 406 429 notsaved : function(postid) { -
src/wp-includes/js/media-editor.js
diff --git src/wp-includes/js/media-editor.js src/wp-includes/js/media-editor.js index ec13796..b2dfd15 100644
648 648 649 649 this._frame = wp.media({ 650 650 state: 'featured-image', 651 states: [ new wp.media.controller.FeaturedImage() ]651 states: [ new wp.media.controller.FeaturedImage() , new wp.media.controller.EditImage() ] 652 652 }); 653 653 654 654 this._frame.on( 'toolbar:create:featured-image', function( toolbar ) { … … 660 660 }); 661 661 }, this._frame ); 662 662 663 this._frame.on( 'content:render:edit-image', function() { 664 var selection = this.state('featured-image').get('selection'), 665 view = new wp.media.view.EditImage( { model: selection.single(), controller: this } ).render(); 666 667 this.content.set( view ); 668 669 // after bringing in the frame, load the actual editor via an ajax call 670 view.loadEditor(); 671 672 }, this._frame ); 673 663 674 this._frame.state('featured-image').on( 'select', this.select ); 664 675 return this._frame; 665 676 }, -
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..86b3927 100644
1000 1000 toolbar: 'featured-image', 1001 1001 title: l10n.setFeaturedImageTitle, 1002 1002 priority: 60, 1003 syncSelection: false1003 syncSelection: true 1004 1004 }, media.controller.Library.prototype.defaults ), 1005 1005 1006 1006 initialize: function() { … … 1132 1132 }); 1133 1133 1134 1134 /** 1135 * wp.media.controller.EditImage 1136 * 1137 * @constructor 1138 * @augments wp.media.controller.State 1139 * @augments Backbone.Model 1140 */ 1141 media.controller.EditImage = media.controller.State.extend({ 1142 defaults: { 1143 id: 'edit-image', 1144 url: '', 1145 menu: false, 1146 content: 'edit-image', 1147 syncSelection: true 1148 }, 1149 1150 activate: function() { 1151 if ( ! this.get('selection') ) { 1152 this.set( 'selection', new media.model.Selection() ); 1153 } 1154 this.syncSelection(); 1155 }, 1156 1157 syncSelection: function() { 1158 var selection = this.get('selection'), 1159 manager = this.frame._selection; 1160 1161 if ( ! this.get('syncSelection') || ! manager || ! selection ) { 1162 return; 1163 } 1164 1165 // If the selection supports multiple items, validate the stored 1166 // attachments based on the new selection's conditions. Record 1167 // the attachments that are not included; we'll maintain a 1168 // reference to those. Other attachments are considered in flux. 1169 if ( selection.multiple ) { 1170 selection.reset( [], { silent: true }); 1171 selection.validateAll( manager.attachments ); 1172 manager.difference = _.difference( manager.attachments.models, selection.models ); 1173 } 1174 1175 // Sync the selection's single item with the master. 1176 selection.single( manager.single ); 1177 } 1178 }); 1179 1180 /** 1135 1181 * wp.media.controller.Embed 1136 1182 * 1137 1183 * @constructor … … 1890 1936 1891 1937 content: { 1892 1938 'embed': 'embedContent', 1939 'edit-image': 'editImageContent', 1893 1940 'edit-selection': 'editSelectionContent' 1894 1941 }, 1895 1942 … … 2040 2087 this.content.set( view ); 2041 2088 }, 2042 2089 2090 editImageContent: function() { 2091 var selection = this.state().get('selection'), 2092 view = new media.view.EditImage( { model: selection.single(), controller: this } ).render(); 2093 2094 this.content.set( view ); 2095 2096 // after bringing in the frame, load the actual editor via an ajax call 2097 view.loadEditor(); 2098 2099 }, 2100 2043 2101 // Toolbars 2044 2102 2045 2103 /** … … 2370 2428 media.view.MediaFrame.Select.prototype.bindHandlers.apply( this, arguments ); 2371 2429 this.on( 'menu:create:image-details', this.createMenu, this ); 2372 2430 this.on( 'content:render:image-details', this.renderImageDetailsContent, this ); 2431 this.on( 'content:render:edit-image', this.editImageContent, this ); 2373 2432 this.on( 'menu:render:image-details', this.renderMenu, this ); 2374 2433 this.on( 'toolbar:render:image-details', this.renderImageDetailsToolbar, this ); 2375 2434 // override the select toolbar … … 2393 2452 toolbar: 'replace', 2394 2453 priority: 80, 2395 2454 displaySettings: true 2396 }) 2455 }), 2456 new media.controller.EditImage( { image: this.image } ) 2397 2457 ]); 2398 2458 }, 2399 2459 … … 2433 2493 2434 2494 }, 2435 2495 2496 editImageContent: function() { 2497 var attachment = this.state().get('image').attachment, 2498 view; 2499 2500 if ( ! attachment ) { 2501 return; 2502 } 2503 2504 view = new media.view.EditImage( { model: attachment, controller: this } ).render(); 2505 2506 this.content.set( view ); 2507 2508 // after bringing in the frame, load the actual editor via an ajax call 2509 view.loadEditor(); 2510 2511 }, 2512 2436 2513 renderImageDetailsToolbar: function() { 2437 2514 this.toolbar.set( new media.view.Toolbar({ 2438 2515 controller: this, … … 5250 5327 } 5251 5328 }, 5252 5329 5253 editAttachment: function() { 5254 this.$el.addClass('needs-refresh'); 5330 editAttachment: function( event ) { 5331 event.preventDefault(); 5332 this.controller.setState( 'edit-image' ); 5255 5333 }, 5256 5334 /** 5257 5335 * @param {Object} event … … 5261 5339 event.preventDefault(); 5262 5340 this.model.fetch(); 5263 5341 } 5342 5264 5343 }); 5265 5344 5266 5345 /** … … 5534 5613 media.view.ImageDetails = media.view.Settings.AttachmentDisplay.extend({ 5535 5614 className: 'image-details', 5536 5615 template: media.template('image-details'), 5537 5616 events: { 5617 'click .edit-attachment': 'editAttachment' 5618 }, 5538 5619 initialize: function() { 5539 5620 // used in AttachmentDisplay.prototype.updateLinkTo 5540 5621 this.options.attachment = this.model.attachment; … … 5574 5655 resetFocus: function() { 5575 5656 this.$( '.caption textarea' ).focus(); 5576 5657 this.$( '.embed-image-settings' ).scrollTop( 0 ); 5658 }, 5659 5660 editAttachment: function( event ) { 5661 event.preventDefault(); 5662 this.controller.setState( 'edit-image' ); 5663 } 5664 }); 5665 5666 5667 media.view.EditImage = media.View.extend({ 5668 5669 className: 'image-editor', 5670 template: media.template('image-editor'), 5671 5672 initialize: function( options ) { 5673 this.editor = window.imageEdit; 5674 this.controller = options.controller; 5675 media.View.prototype.initialize.apply( this, arguments ); 5676 }, 5677 5678 prepare: function() { 5679 return this.model.toJSON(); 5680 }, 5681 5682 render: function() { 5683 media.View.prototype.render.apply( this, arguments ); 5684 return this; 5685 }, 5686 5687 loadEditor: function() { 5688 this.editor.open( this.model.get('id'), this.model.get('nonces').edit, this ); 5689 }, 5690 5691 cancel: function() { 5692 var lastState = this.controller.lastState(); 5693 this.controller.setState( lastState ); 5577 5694 } 5695 5578 5696 }); 5697 5579 5698 }(jQuery)); -
src/wp-includes/media-template.php
diff --git src/wp-includes/media-template.php src/wp-includes/media-template.php index daf8c29..752502c 100644
function wp_print_media_templates() { 560 560 <div class="thumbnail"> 561 561 <img src="{{ data.model.url }}" draggable="false" /> 562 562 </div> 563 <# if ( data.attachment ) { #> 564 <input type="button" class="edit-attachment button" value="<?php esc_attr_e( 'Edit Image' ); ?>" /> 565 <# } #> 563 566 564 567 <div class="setting url"> 565 568 <?php // might want to make the url editable if it isn't an attachment ?> … … function wp_print_media_templates() { 649 652 </div> 650 653 </div> 651 654 </script> 655 656 <script type="text/html" id="tmpl-image-editor"> 657 <div id="media-head-{{{ data.id }}}"></div> 658 <div id="image-editor-{{{ data.id }}}"></div> 659 </script> 652 660 <?php 653 661 654 662 /** -
src/wp-includes/media.php
diff --git src/wp-includes/media.php src/wp-includes/media.php index ebcfa0e..af4df99 100644
function wp_prepare_attachment_for_js( $attachment ) { 2135 2135 'nonces' => array( 2136 2136 'update' => false, 2137 2137 'delete' => false, 2138 'edit' => false 2138 2139 ), 2139 2140 'editLink' => false, 2140 2141 ); 2141 2142 2142 2143 if ( current_user_can( 'edit_post', $attachment->ID ) ) { 2143 2144 $response['nonces']['update'] = wp_create_nonce( 'update-post_' . $attachment->ID ); 2145 $response['nonces']['edit'] = wp_create_nonce( 'image_editor-' . $attachment->ID ); 2144 2146 $response['editLink'] = get_edit_post_link( $attachment->ID, 'raw' ); 2145 2147 } 2146 2148 … … function wp_enqueue_media( $args = array() ) { 2371 2373 2372 2374 wp_enqueue_script( 'media-editor' ); 2373 2375 wp_enqueue_style( 'media-views' ); 2376 wp_enqueue_style( 'imgareaselect' ); 2374 2377 wp_plupload_default_settings(); 2375 2378 2376 2379 require_once ABSPATH . WPINC . '/media-template.php'; -
src/wp-includes/script-loader.php
diff --git src/wp-includes/script-loader.php src/wp-includes/script-loader.php index d696b13..a3dc3b7 100644
function wp_default_scripts( &$scripts ) { 395 395 // To enqueue media-views or media-editor, call wp_enqueue_media(). 396 396 // Both rely on numerous settings, styles, and templates to operate correctly. 397 397 $scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable' ), false, 1 ); 398 $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 );398 $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views', 'image-edit' ), false, 1 ); 399 399 $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'media-models' ), false, 1 ); 400 400 401 401 if ( is_admin() ) {