Ticket #21811: trac-21811-image-edit-view-01.patch
File trac-21811-image-edit-view-01.patch, 8.7 KB (added by , 11 years ago) |
---|
-
src/wp-admin/js/image-edit.js
5 5 iasapi : {}, 6 6 hold : {}, 7 7 postid : '', 8 _view : {}, 8 9 9 10 intval : function(f) { 10 11 return f | 0; … … 287 288 }); 288 289 }, 289 290 290 open : function(postid, nonce) { 291 open : function( postid, nonce, view ) { 292 _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 … … 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 ( _view && 'object' == typeof _view ){ 407 _view.controller.setState( _view.controller.lastState() ); 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-views.js
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 this.syncSelection(); 1082 }, 1083 1084 syncSelection: function() { 1085 var selection = this.get('selection'), 1086 manager = this.frame._selection; 1087 1088 if ( ! this.get('syncSelection') || ! manager || ! selection ) { 1089 return; 1090 } 1091 1092 // If the selection supports multiple items, validate the stored 1093 // attachments based on the new selection's conditions. Record 1094 // the attachments that are not included; we'll maintain a 1095 // reference to those. Other attachments are considered in flux. 1096 if ( selection.multiple ) { 1097 selection.reset( [], { silent: true }); 1098 selection.validateAll( manager.attachments ); 1099 manager.difference = _.difference( manager.attachments.models, selection.models ); 1100 } 1101 1102 // Sync the selection's single item with the master. 1103 selection.single( manager.single ); 1104 } 1105 }); 1106 1107 /** 1065 1108 * wp.media.controller.Embed 1066 1109 * 1067 1110 * @constructor … … 1740 1783 menu: 'gallery' 1741 1784 }), 1742 1785 1743 new media.controller.GalleryAdd() 1786 new media.controller.GalleryAdd(), 1787 1788 new media.controller.EditImage( { selection: options.selection } ) 1744 1789 ]); 1745 1790 1746 1791 … … 1768 1813 1769 1814 content: { 1770 1815 'embed': 'embedContent', 1816 'edit-image': 'editImageContent', 1771 1817 'edit-selection': 'editSelectionContent' 1772 1818 }, 1773 1819 … … 1866 1912 this.content.set( view ); 1867 1913 }, 1868 1914 1915 editImageContent: function() { 1916 var selection = this.state().get('selection'), 1917 view = new media.view.EditImage( { model: selection.single() } ).render(); 1918 1919 this.content.set( view ); 1920 1921 // after bringing in the frame, load the actual editor via an ajax call 1922 view.loadEditor(); 1923 }, 1924 1869 1925 // Toolbars 1870 1926 1871 1927 /** … … 2037 2093 media.view.MediaFrame.Select.prototype.bindHandlers.apply( this, arguments ); 2038 2094 this.on( 'menu:create:image-details', this.createMenu, this ); 2039 2095 this.on( 'content:render:image-details', this.renderImageDetailsContent, this ); 2096 this.on( 'content:render:edit-image', this.editImageContent, this ); 2040 2097 this.on( 'menu:render:image-details', this.renderMenu, this ); 2041 2098 this.on( 'toolbar:render:image-details', this.renderImageDetailsToolbar, this ); 2042 2099 // override the select toolbar … … 2060 2117 toolbar: 'replace', 2061 2118 priority: 80, 2062 2119 displaySettings: true 2063 }) 2120 }), 2121 new media.controller.EditImage( { image: this.image } ) 2064 2122 ]); 2065 2123 }, 2066 2124 … … 2100 2158 2101 2159 }, 2102 2160 2161 editImageContent: function() { 2162 var attachment = this.state().get('image').attachment, 2163 view; 2164 2165 if ( ! attachment ) { 2166 return; 2167 } 2168 2169 view = new media.view.EditImage({ 2170 controller: this, 2171 model: attachment 2172 }).render(); 2173 2174 this.content.set( view ); 2175 2176 // after bringing in the frame, load the actual editor via an ajax call 2177 view.loadEditor(); 2178 2179 }, 2180 2103 2181 renderImageDetailsToolbar: function() { 2104 2182 this.toolbar.set( new media.view.Toolbar({ 2105 2183 controller: this, … … 4895 4973 } 4896 4974 }, 4897 4975 4898 editAttachment: function() { 4899 this.$el.addClass('needs-refresh'); 4976 editAttachment: function( event ) { 4977 event.preventDefault(); 4978 this.controller.setState( 'edit-image' ); 4900 4979 }, 4901 4980 /** 4902 4981 * @param {Object} event … … 4906 4985 event.preventDefault(); 4907 4986 this.model.fetch(); 4908 4987 } 4988 4909 4989 }); 4910 4990 4911 4991 /** … … 5180 5260 className: 'image-details', 5181 5261 template: media.template('image-details'), 5182 5262 5263 events: { 5264 'click .edit-attachment': 'editAttachment' 5265 }, 5266 5183 5267 initialize: function() { 5184 5268 // used in AttachmentDisplay.prototype.updateLinkTo 5185 5269 this.options.attachment = this.model.attachment; … … 5219 5303 resetFocus: function() { 5220 5304 this.$( '.caption textarea' ).focus(); 5221 5305 this.$( '.embed-image-settings' ).scrollTop( 0 ); 5306 }, 5307 5308 editAttachment: function( event ) { 5309 event.preventDefault(); 5310 this.controller.setState( 'edit-image' ); 5222 5311 } 5223 5312 }); 5313 5314 5315 media.view.EditImage = media.View.extend({ 5316 className: 'image-editor', 5317 template: media.template('image-editor'), 5318 5319 initialize: function() { 5320 5321 this.editor = window.imageEdit; 5322 media.View.prototype.initialize.apply( this, arguments ); 5323 }, 5324 5325 prepare: function() { 5326 return this.model.toJSON(); 5327 }, 5328 5329 render: function() { 5330 media.View.prototype.render.apply( this, arguments ); 5331 return this; 5332 }, 5333 5334 loadEditor: function() { 5335 this.editor.open( this.model.get('id'), this.model.get('nonces').edit, this ); 5336 } 5337 5338 }); 5339 5224 5340 }(jQuery)); -
src/wp-includes/media-template.php
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 ?> … … 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
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 -
src/wp-includes/script-loader.php
385 385 // To enqueue media-views or media-editor, call wp_enqueue_media(). 386 386 // Both rely on numerous settings, styles, and templates to operate correctly. 387 387 $scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable' ), false, 1 ); 388 $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 );388 $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views', 'image-edit' ), false, 1 ); 389 389 $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'media-models' ), false, 1 ); 390 390 391 391 if ( is_admin() ) {