Ticket #21811: 21811-modal-04.patch
File 21811-modal-04.patch, 10.8 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..35a471c 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 = { 397 400 398 401 this.iasapi = {}; 399 402 this.hold = {}; 400 $('#image-editor-' + postid).fadeOut('fast', function() { 401 $('#media-head-' + postid).fadeIn('fast'); 402 $(this).empty(); 403 }); 403 404 // If we've loaded the editor in the context of a Media Modal, then switch to the previous view, 405 // whatever that might have been. 406 if ( this._view && 'object' === typeof this._view ){ 407 this._view.cancel(); 408 } 409 410 // In case we are not accessing the image editor in the context of a View, close the editor the old-skool way 411 else { 412 $('#image-editor-' + postid).fadeOut('fast', function() { 413 $('#media-head-' + postid).fadeIn('fast'); 414 $(this).empty(); 415 }); 416 } 417 418 404 419 }, 405 420 406 421 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 9ae3f83..faf373e 100644
562 562 563 563 this._frame = wp.media({ 564 564 state: 'featured-image', 565 states: [ new wp.media.controller.FeaturedImage() ]565 states: [ new wp.media.controller.FeaturedImage() , new wp.media.controller.EditImage() ] 566 566 }); 567 567 568 568 this._frame.on( 'toolbar:create:featured-image', function( toolbar ) { … … 574 574 }); 575 575 }, this._frame ); 576 576 577 this._frame.on( 'content:render:edit-image', function() { 578 var selection = this.state('featured-image').get('selection'), 579 view = new wp.media.view.EditImage( { model: selection.single(), controller: this } ).render(); 580 581 this.content.set( view ); 582 583 // after bringing in the frame, load the actual editor via an ajax call 584 view.loadEditor(); 585 586 }, this._frame ); 587 577 588 this._frame.state('featured-image').on( 'select', this.select ); 578 589 return this._frame; 579 590 }, -
src/wp-includes/js/media-views.js
diff --git src/wp-includes/js/media-views.js src/wp-includes/js/media-views.js index d32b996..59368b4 100644
930 930 toolbar: 'featured-image', 931 931 title: l10n.setFeaturedImageTitle, 932 932 priority: 60, 933 syncSelection: false933 syncSelection: true 934 934 }, media.controller.Library.prototype.defaults ), 935 935 936 936 initialize: function() { … … 1062 1062 }); 1063 1063 1064 1064 /** 1065 * wp.media.controller.EditImage 1066 * 1067 * @constructor 1068 * @augments wp.media.controller.State 1069 * @augments Backbone.Model 1070 */ 1071 media.controller.EditImage = media.controller.State.extend({ 1072 defaults: { 1073 id: 'edit-image', 1074 url: '', 1075 menu: false, 1076 content: 'edit-image', 1077 syncSelection: true 1078 }, 1079 1080 activate: function() { 1081 if ( ! this.get('selection') ) { 1082 this.set( 'selection', new media.model.Selection() ); 1083 } 1084 this.syncSelection(); 1085 }, 1086 1087 syncSelection: function() { 1088 var selection = this.get('selection'), 1089 manager = this.frame._selection; 1090 1091 if ( ! this.get('syncSelection') || ! manager || ! selection ) { 1092 return; 1093 } 1094 1095 // If the selection supports multiple items, validate the stored 1096 // attachments based on the new selection's conditions. Record 1097 // the attachments that are not included; we'll maintain a 1098 // reference to those. Other attachments are considered in flux. 1099 if ( selection.multiple ) { 1100 selection.reset( [], { silent: true }); 1101 selection.validateAll( manager.attachments ); 1102 manager.difference = _.difference( manager.attachments.models, selection.models ); 1103 } 1104 1105 // Sync the selection's single item with the master. 1106 selection.single( manager.single ); 1107 } 1108 }); 1109 1110 /** 1065 1111 * wp.media.controller.Embed 1066 1112 * 1067 1113 * @constructor … … 1740 1786 menu: 'gallery' 1741 1787 }), 1742 1788 1743 new media.controller.GalleryAdd() 1789 new media.controller.GalleryAdd(), 1790 1791 new media.controller.EditImage( { selection: options.selection } ) 1744 1792 ]); 1745 1793 1746 1794 … … 1768 1816 1769 1817 content: { 1770 1818 'embed': 'embedContent', 1819 'edit-image': 'editImageContent', 1771 1820 'edit-selection': 'editSelectionContent' 1772 1821 }, 1773 1822 … … 1866 1915 this.content.set( view ); 1867 1916 }, 1868 1917 1918 editImageContent: function() { 1919 var selection = this.state().get('selection'), 1920 view = new media.view.EditImage( { model: selection.single(), controller: this } ).render(); 1921 1922 this.content.set( view ); 1923 1924 // after bringing in the frame, load the actual editor via an ajax call 1925 view.loadEditor(); 1926 1927 }, 1928 1869 1929 // Toolbars 1870 1930 1871 1931 /** … … 2037 2097 media.view.MediaFrame.Select.prototype.bindHandlers.apply( this, arguments ); 2038 2098 this.on( 'menu:create:image-details', this.createMenu, this ); 2039 2099 this.on( 'content:render:image-details', this.renderImageDetailsContent, this ); 2100 this.on( 'content:render:edit-image', this.editImageContent, this ); 2040 2101 this.on( 'menu:render:image-details', this.renderMenu, this ); 2041 2102 this.on( 'toolbar:render:image-details', this.renderImageDetailsToolbar, this ); 2042 2103 // override the select toolbar … … 2060 2121 toolbar: 'replace', 2061 2122 priority: 80, 2062 2123 displaySettings: true 2063 }) 2124 }), 2125 new media.controller.EditImage( { image: this.image } ) 2064 2126 ]); 2065 2127 }, 2066 2128 … … 2100 2162 2101 2163 }, 2102 2164 2165 editImageContent: function() { 2166 var attachment = this.state().get('image').attachment, 2167 view; 2168 2169 if ( ! attachment ) { 2170 return; 2171 } 2172 2173 view = new media.view.EditImage( { model: attachment, controller: this } ).render(); 2174 2175 this.content.set( view ); 2176 2177 // after bringing in the frame, load the actual editor via an ajax call 2178 view.loadEditor(); 2179 2180 }, 2181 2103 2182 renderImageDetailsToolbar: function() { 2104 2183 this.toolbar.set( new media.view.Toolbar({ 2105 2184 controller: this, … … 4899 4978 } 4900 4979 }, 4901 4980 4902 editAttachment: function() { 4903 this.$el.addClass('needs-refresh'); 4981 editAttachment: function( event ) { 4982 event.preventDefault(); 4983 this.controller.setState( 'edit-image' ); 4904 4984 }, 4905 4985 /** 4906 4986 * @param {Object} event … … 4910 4990 event.preventDefault(); 4911 4991 this.model.fetch(); 4912 4992 } 4993 4913 4994 }); 4914 4995 4915 4996 /** … … 5183 5264 media.view.ImageDetails = media.view.Settings.AttachmentDisplay.extend({ 5184 5265 className: 'image-details', 5185 5266 template: media.template('image-details'), 5186 5267 events: { 5268 'click .edit-attachment': 'editAttachment' 5269 }, 5187 5270 initialize: function() { 5188 5271 // used in AttachmentDisplay.prototype.updateLinkTo 5189 5272 this.options.attachment = this.model.attachment; … … 5223 5306 resetFocus: function() { 5224 5307 this.$( '.caption textarea' ).focus(); 5225 5308 this.$( '.embed-image-settings' ).scrollTop( 0 ); 5309 }, 5310 5311 editAttachment: function( event ) { 5312 event.preventDefault(); 5313 this.controller.setState( 'edit-image' ); 5314 } 5315 }); 5316 5317 5318 media.view.EditImage = media.View.extend({ 5319 5320 className: 'image-editor', 5321 template: media.template('image-editor'), 5322 5323 initialize: function( options ) { 5324 this.editor = window.imageEdit; 5325 this.controller = options.controller; 5326 media.View.prototype.initialize.apply( this, arguments ); 5327 }, 5328 5329 prepare: function() { 5330 return this.model.toJSON(); 5331 }, 5332 5333 render: function() { 5334 media.View.prototype.render.apply( this, arguments ); 5335 return this; 5336 }, 5337 5338 loadEditor: function() { 5339 this.editor.open( this.model.get('id'), this.model.get('nonces').edit, this ); 5340 }, 5341 5342 cancel: function() { 5343 var lastState = this.controller.lastState(); 5344 this.controller.setState( lastState ); 5226 5345 } 5346 5227 5347 }); 5348 5228 5349 }(jQuery)); -
src/wp-includes/media-template.php
diff --git src/wp-includes/media-template.php src/wp-includes/media-template.php index 28f4a1a..68a64a9 100644
function wp_print_media_templates() { 508 508 <div class="thumbnail"> 509 509 <img src="{{ data.model.url }}" draggable="false" /> 510 510 </div> 511 <# if ( data.attachment ) { #> 512 <input type="button" class="edit-attachment button" value="<?php esc_attr_e( 'Edit Image' ); ?>" /> 513 <# } #> 511 514 512 515 <div class="setting url"> 513 516 <?php // might want to make the url editable if it isn't an attachment ?> … … function wp_print_media_templates() { 597 600 </div> 598 601 </div> 599 602 </script> 603 604 <script type="text/html" id="tmpl-image-editor"> 605 <div id="media-head-{{{ data.id }}}"></div> 606 <div id="image-editor-{{{ data.id }}}"></div> 607 </script> 600 608 <?php 601 609 602 610 /** -
src/wp-includes/media.php
diff --git src/wp-includes/media.php src/wp-includes/media.php index aac3c44..a33db8a 100644
function wp_prepare_attachment_for_js( $attachment ) { 1869 1869 'nonces' => array( 1870 1870 'update' => false, 1871 1871 'delete' => false, 1872 'edit' => false 1872 1873 ), 1873 1874 'editLink' => false, 1874 1875 ); 1875 1876 1876 1877 if ( current_user_can( 'edit_post', $attachment->ID ) ) { 1877 1878 $response['nonces']['update'] = wp_create_nonce( 'update-post_' . $attachment->ID ); 1879 $response['nonces']['edit'] = wp_create_nonce( 'image_editor-' . $attachment->ID ); 1878 1880 $response['editLink'] = get_edit_post_link( $attachment->ID, 'raw' ); 1879 1881 } 1880 1882 … … function wp_enqueue_media( $args = array() ) { 2083 2085 2084 2086 wp_enqueue_script( 'media-editor' ); 2085 2087 wp_enqueue_style( 'media-views' ); 2088 wp_enqueue_style( 'imgareaselect' ); 2086 2089 wp_plupload_default_settings(); 2087 2090 2088 2091 require_once ABSPATH . WPINC . '/media-template.php'; … … function maybe_regenerate_attachment_metadata( $attachment ) { 2258 2261 delete_transient( $regeneration_lock ); 2259 2262 } 2260 2263 } 2261 } 2262 No newline at end of file 2264 } -
src/wp-includes/script-loader.php
diff --git src/wp-includes/script-loader.php src/wp-includes/script-loader.php index 34e95fd..0a8ec45 100644
function wp_default_scripts( &$scripts ) { 389 389 // To enqueue media-views or media-editor, call wp_enqueue_media(). 390 390 // Both rely on numerous settings, styles, and templates to operate correctly. 391 391 $scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable' ), false, 1 ); 392 $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 );392 $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views', 'image-edit' ), false, 1 ); 393 393 $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'media-models' ), false, 1 ); 394 394 395 395 if ( is_admin() ) {